git解决冲突的方法

1.

You are not currently on a branch, so I cannot use any

症状:有一次pull的时候又出现冲突,这回用“git reset --hard FETCH_HEAD”方法都不行了,出现:

$ git pull
You are not currently on a branch, so I cannot use any
'branch.<branchname>.merge' in your configuration file.
Please specify which remote branch you want to use on the command
line and try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details.
解决方法:

首先git checkout -b temp

其次git checkout master

即可恢复到master repository的状态,然后就可以pull了

2.

使用Git时,在pull、merge、rebase的过程中,经常会遇到conflict的情况。

遇到conflict时,以上处理过程会终端,并且命令行中显示(xxx|MERGING)的状态(Windows下Git Bash中显示的状态)。

命令行下解决冲突的方法为:

使用任意的文本编辑工具编辑有冲突的文件,去除冲突标记(就是>>>>>>>> ======= <<<<<<这样的东西),并把文本冲突解决掉。

然后使用git add 有冲突的文件,这时文件的冲突标记就变成了修改标记了(在windows下安装TortoiseGit就能看到文件图标的变化了)。

将所有有冲突的文件解决完后,使用git commit -a -m "Xxx"提交就算完成整个合并过程了。

posted @ 2017-04-18 18:16  三贞九烈  阅读(2862)  评论(0编辑  收藏  举报