git bash、eclipse中git插件提交出現衝突以及解決辦法

git bash提交到本地倉庫後,執行git push origin時報錯

error: failed to push some refs to 'https://github.com/XiangNo1/gtitest.git'
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.

解決辦法:

1.執行命令將遠程代碼拉到本地:git pull origin,會提示有衝突需要解決的文件

Auto-merging test.txt
CONFLICT (content): Merge conflict in test.txt
Automatic merge failed; fix conflicts and then commit the result.

2.打開這個test.txt測試文件,如下顯示:

this is test
test111111
test222222222
test333333333333
<<<<<<< HEAD
test9999999
=======
test88888888888888
>>>>>>> db5f7ccd0d4fc1822f13c60cb349e8e89dde4ea7

3.此時只需要將文件修改,將衝突部分去掉然後改成自己想要的,再執行git add和gitcommit 然後git push即可解決衝突。

git bash,直接執行git pull origin時報錯

error: Your local changes to the following files would be overwritten by merge:
        test.txt
Please commit your changes or stash them before you merge.
Aborting
Updating db5f7cc..937df47

解決辦法:

1.將本地文件提交到本地倉庫(git add、git commit兩步)

2.執行git pull origin

$ git pull origin
Auto-merging test.txt
CONFLICT (content): Merge conflict in test.txt
Automatic merge failed; fix conflicts and then commit the result.

3.打開這個test.txt測試文件,如下顯示:

this is test
test111111
test222222222
test333333333333
<<<<<<< HEAD
test88888888888888
test100101010101
=======
test9999999
test88888888888888
>>>>>>> 937df476924fa50133d370f652d52178e53a0213

4.此時只需要將文件修改,將衝突部分去掉然後改成自己想要的,再執行git add和gitcommit 然後git push即可解決衝突。

eclipse的git插件解決衝突

(eclipse 用git插件首先將這個對勾去掉:設置-team-git-committing-use staging view....)

eclipse的git插件解決衝突方法:

1.pull,如果pull出錯說明有衝突文件。

2.同步一下工作狀態,查看一下哪些文件有衝突。

3.commit到本地倉庫。

4.pull。文件顯示衝突區域。

5.解決衝突,並且add to index。

6.commit到本地倉庫。

7.push到遠程倉庫。

(注意:期間會commit兩次,這兩次的日誌都會顯示出來。)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章