簡體   English   中英

git pull origin master 出現合並沖突:我該怎么辦?

[英]git pull origin master gives merge conflict: what should I do?

我正在從 master 創建的分支 ( my-branch ) 上工作。

$ git checkout -b my-branch

我編輯了一些文件,然后將它們簽入新分支:

$ git commit -a -m 'Add new feature'

然后我從 master 那里拉出來(我不完全確定我為什么這樣做,或者它是否是好的做法):

$ git pull origin master 

但是拉動給了我很多錯誤信息:

   From github.com
 * branch            master     -> FETCH_HEAD
Auto-merging styles/common/module_more_info.scss
CONFLICT (add/add): Merge conflict in styles/common/module_more_info.scss
Auto-merging app/support/stagecraft_stub/responses/cloud.json
CONFLICT (content): Merge conflict in app/support/stagecraft_stub/responses/cloud.json
Auto-merging app/support/backdrop_stub/response_fetcher.js
CONFLICT (content): Merge conflict in app/support/backdrop_stub/response_fetcher.js
Automatic merge failed; fix conflicts and then commit the result.
vagrant@pp-development-1:/var/apps/spotlight$ git status

現在運行git status顯示許多更改的文件:

# 在分支 my-branch

# Changes to be committed:
#
#       modified:   CONTRIBUTING.md
#       modified:   README.md
#       modified:   app/appBuilder.js
[lots more files]
#
# Unmerged paths:
#   (use "git add/rm <file>..." as appropriate to mark resolution)
#
#       both modified:      app/support/backdrop_stub/response_fetcher.js
#       both modified:      app/support/stagecraft_stub/responses/cloud.json
#       both added:         styles/common/module_more_info.scss

首先,發生了什么,其次,我該怎么辦?

如果我嘗試查看任何上層文件列表中的差異,我會得到空輸出,這令人困惑(如果沒有差異,為什么要我提交文件?):

$ git diff CONTRIBUTING.md
$

我應該查看未Unmerged paths下的三個文件,然后將其作為合並提交提交嗎? 更新:最重要的是,我可以將它推送到我的分支而不會弄亂主分支嗎?

我似乎無法回滾上次提交。

不要使用合並工具,因為它會讓你感到困惑。 請備份您當前的代碼並恢復您在當前分支中的更改。 然后檢查您的主(開發),獲取最新信息,然后重寫您的更改,然后推送。

首先,您需要在您的 github 中輸入gitk --all哪個分支當前將通過顯示的頂部打開

那么你需要revert的是或rebase你的服務器最新代碼的代碼:

然后命令以下步驟將您的分支推送到服務器主服務器。

git status

git add .

git status

git commit -a -m "Comments"

git push origin yourbranchname

這就是全部...

基本上,是的。 git mergetool可能會有所幫助。 它只是打開一個包含需要您注意的文件的合並工具,然后將它們添加到索引中。 通過簡單的git commit您可以創建合並沖突。

你總是可以通過執行git reset --hard HEAD回到拉取前的狀態。

可能發生的事情是:

  1. 其他人正在編輯或將其代碼與 Master 合並。
  2. 您的字符集與上一個編輯 Master 的用戶不同。

解決辦法是:

git mergetool <you can left here blank your choose a mergetool from those you have installed in your machine>

所以首先配置你的合並工具。 我建議安裝這個

  • 現在您的更改與遠程更改發生沖突,您必須解決沖突。 為每個文件做:

    • git合並工具

    • 保存文件。

現在您對 git 說您知道存在沖突,但您想以使用合並工具的方式解決它們。 所以現在沖突已經解決了。

git status

現在您必須提交已解析的文件,然后推送它們。

附注。 另一種方法是存儲您的更改而不是提交,然后從源中提取,然后彈出您的存儲。

git stash save
git pull
git stash pop
git commit
git pull

但是從我讀到的內容來看,如果您確定要進行更改,則必須像以前一樣提交它們,然后合並它們。 合並很常見,您必須知道如何處理。

打開沖突文件並解決刪除差異。

然后:

git add . 
git commit -am "resolve conflicts"
git push origin master

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM