在使用git的過程中經常需要使用到git pull命令,在更新遠端代碼的同時如果與本地代碼產生沖突了,
那么沖突的文件中就出現了需要手動合並的部分,而git pull --rebase不同的地方則是當有這些沖突存在時,
git幫我們自動創建了一個新的分支,並且git告訴你接下來你要在這個新的分支上處理這個沖突,
此時執行git status命令后可以看到首要的提示是這樣的:
rebase in progress; onto 24f42c6
You are currently rebasing branch 'master' on '24f42c6'.
(fix conflicts and then run "git rebase --continue")
並且git還告訴我們 fix conflicts and then run "git rebase --continue",意思是解決沖突然后執行git rebase --continue命令,
其實git rebase --continue的正確操作應該是確認處理好沖突后則將調整好的文件添加到暫存區,並執行git rebase --continue命令告訴git,我已經解決好沖突了,
並且已經將處理后的文件添加到了暫存區,現在可以將這些文件commit了,
簡單來講就是正常的解決沖突過程是
1,git add .
2,git commit -m "..."
3,git push時因為本地倉庫代碼與遠程倉代碼有沖突,所以接下來
4,git pull拉取遠程代碼,而沖突需要手動解決
5,解決好后重新進行git add . git commit -m".." git push
而git pull 這一步如果加上了 --rebase的選項,那么第5步操作將變成如下
git add .
git rebase --continue
git push
所以git pull --rebase用在合並代碼的時候其作用就是在一個隨機創建的分支上處理沖突,避免了直接污染原來的分區
