簡體   English   中英

Git pull覆蓋並且不會在同一分支上合並或確認沖突(master)

[英]Git pull overwrites and does not merge or acknowledge conflict on same branch (master)

背景:

我有我認為的簡單場景。 我已經在本地提交了更改,現在我想將遠程的,在同一個分支(在我之前)的內容合並到本地的工作目錄中。

git branch -vv --list --all給出以下內容:

  master                79d9d4e [origin/master: behind 7] Footprint UI working
  remotes/origin/HEAD   -> origin/master
  remotes/origin/master a86a1a9 Added sample data to webpage

特別是我想合並一個文件。 這是diff: git diff --stat a86a1a9 79d9d4e views/footprint.handlebars

views/footprint.handlebars | 65 +++++++++++++++++++++++++++++++++--------------------------------
 1 file changed, 33 insertions(+), 32 deletions(-)

但是當我運行git pull ,我本地提交中的文件版本會被遠程的文件覆蓋。 用更詳細的術語:

$ git fetch -v origin  

From github.com:githubusername/foo
 = [up to date]      master     -> origin/master
$ git merge origin  
Updating 79d9d4e..a86a1a9
Fast-forward
...
 views/footprint.handlebars    | 65 ++++++++++++++++++++++++++++++++---------------------------------
...
 6 files changed, 220 insertions(+), 59 deletions(-)
 create mode 100644 static/search.js
 create mode 100644 views/search.handlebars

我已閱讀以下帖子:

  1. git merge覆蓋內容
  2. Git merge master進入開發分支是覆蓋,而不是合並

並嘗試過這些命令:

  1. git pull --rebase覆蓋文件的本地版本
  2. git merge -s recursive -X ours覆蓋了本地版本的文件
  3. git merge -s ours提示提交消息,然后覆蓋遠程更改
  4. git rebase remotes/origin/master表示它將“重播我的工作”,但仍會覆蓋它
  5. git merge --no-ff --no-commit字面報告“自動合並順利;在提交請求之前停止”,當它被覆蓋文件時

(運行上述各項后,我檢查了有問題的文件,並注意到它已被覆蓋,運行git reset --hard master@{"5 minutes ago"}

$ git config --list  

redential.helper=osxkeychain
user.name=My Name
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.precomposeunicode=true
remote.origin.url=git@github.com:githubusername/foo.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
user.email=email@address.com
remote.heroku.url=https://git.heroku.com/foo.git
remote.heroku.fetch=+refs/heads/*:refs/remotes/heroku/*
$ git log --oneline --decorate --simplify-by-decoration --all -10  

a86a1a9 (origin/master, origin/HEAD) Added sample data to webpage
79d9d4e (HEAD -> master) Footprint UI working
c53160d Initial commit
$git log --format="%h %ci %cn" views/footprint.handlebars

79d9d4e 2019-03-12 19:04:08 -0400 chb
fada3fa 2019-03-10 13:59:41 -0700 JA
9641499 2019-03-08 16:48:14 -0800 JA
1759509 2019-03-08 12:32:08 -0800 GitHub
bfe443e 2019-03-07 16:41:18 -0800 JA

git version 2.17.2 (Apple Git-113)

題:

為什么這個沖突沒有被git標記,相應的標記( <<<<<<< HEAD=======>>>>>>> )被添加到相關文件中?

懷疑對合並應該做什么有誤解。 (注意重點,並忍受我)

如果有的話,讓我們清楚一點。

我們最好關注文件views/footprint.handlebars 它是在初始提交和本地提交之間更改的嗎? 在初始提交和origin/master 都?

如果沒有更改它,那么合並后您的文件會反映其更改的事實是預期的。

如果他們沒有更改它,並且您的更改版本被合並后的初始提交中的“舊”版本覆蓋,那么現在這是一個奇怪的行為進行調查。

如果您和他們都對文件進行了更改,但是在不同的非沖突點 ,則最終結果應包含來自雙方的更改,而不會發生沖突。 我不會稱之為“覆蓋”。


最后,如果你實際上想要保持這個文件處於你最近的本地提交中的確切狀態,你必須像你暗示的一樣非常乏味的事情,使合並沖突,但這不是什么大不了的事:

git checkout master
git fetch
git merge --no-commit origin/master
git checkout HEAD -- views/footprint.handlebars
git commit -am "Kept file views/footprint.handlebars as per commit 79d9d4e"

給我們一些反饋,我會編輯調整。 (可能明天,但是;-)

評論后補充:

我幾乎無用的言論下同意以下 我沒有從你原來的問題中得到你和你的同事提交之間的文件來回反復(正如你在這里添加的那樣)。

現在,恢復所需更改和他們所需更改的解決方案可能是檢查文件歷史記錄,然后從初始共享狀態小心地重建內容,但根據您的上下文,很難建議最佳公式。 如果同事可以和你一起解決,你可能會避免很多麻煩。

結語補充:

對於甜蜜的甜蜜結局感到抱歉,我完全理解你會更喜歡更智能的答案/解決方案。 感謝所有富有洞察力的評論,感謝您和其他所有人。

暫無
暫無

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

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