git 实用命令(不定期更新)

①git 提交的文件带空格,出现无法提交情况。

例:text.txt 可以正常提交

       git add  text.txt

       git commit  -m"add file text,txt"

       如果文件名出现空格,提交失败

       t ext.txt

       解决:加双引号 

       git add "t ext.txt"

       git commit -m"add file t ext.txt"

②新建文档,带文件名带中文字符,中文文件名出现乱码,无法提交。

修改全局配置

git config --global core.quotepath false

(在 git bash  右键--option 选择 utf-8 无效。

③ 新建本地库,同时建立远程库,git push origin master 出现异常,显示无法推送

git remote add origin git@github:XXX/xxx.git 

git push origin master 

报错

解决:

git pull --rebase origin master

问题解决

④码云绑定本地库时出现(其实就是known hosts)(参考https://blog.csdn.net/lindexi_gd/article/details/52554159

The authenticity of host 'gitee.com (116.XXX.XXX.XX)' can't be established.
ECDSA key fingerprint is SHA256:FYABDC9AUDIB/yakaXgrQp+hshsshshbmjXXXXc(类似).
Are you sure you want to continue connecting (yes/no)?

直接敲回车的话,无论修改或者重新添加SSH.都是出错的,需要手动yes

Permanently added 'gitee.com,161.xxx.xxx.xx' (ECDSA) to the list of known hosts

 

此时直接git  push origin master会出现问题

新版本git 当发现出现本地库与远程库想合并而没有共同的commit时:

(其实由于本地库之前是关联github,后面解除关联,本地库已经是有多次提交,其中README.md与刚新建的远程README.md有不同,实际代码库转移不应该按照这个路线,出现了一下一系列的问题。同时,发现转移过去后,提交历史会重新显示出来)

然后如果直接push ,会出现新问题,

error: failed to push some refs to 'git@gitee.com:xxxxxx/xxxxxx'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

(本地README.md需要merge)
 "git pull origin master --allow-unrelated-histories"

之后git status 出现

Unmerged paths:
  (use "git add <file>..." to mark resolution)

        both added:      README.md

直接push 出现

! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@gitee.com:lishizhongheng/blot_improve'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

修改本地冲突
git add README.md

git commit -m"add READMD.md"

重新提交,问题解决。

⑤ git push origin master 

提示“everything up to date ”

尝试使用[ git add .] + [git commit -m"add xxx" ] 任然出现

尝试新建分支[git branch dev2 ] --git add .--git commit -m""--git checkout master --git merge dev2 --git branch D dev2 --git push origin master 问题为解决

最后直接新建 .txt 文档,修改提交本地库,再次 git  push origin master --成功 

⑤事实上,github 和 码云是可以使用相同的id_rsa.pub

一直尝试着独立生成码云的公钥,结果一直出现没有权限的提示,直接使用github的公钥,问题解决。


⑥如果我们要将本地仓库与远程仓库关联,可以通过Git命令:git remote add origin [远程仓库地址]。

本地新建库,然后通过关联远程库,可进行远程推送,通知可以查看该远程库的提交记录.

.

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值