簡體   English   中英

git 是否在 master 上重置 HEAD~ 自動合並分支合並沖突

[英]Does git reset HEAD~ on master automatically merge a branch merge conflict

git 是否會在 master 上重置 HEAD~ 自動合並分支合並沖突?

我有一個分支 A 並試圖與 MASTER 合並。 但是發生了合並沖突。 所以我結帳到 MASTER 並運行 git reset HEAD~。

我在 MASTER 上運行了 git 狀態,發現分支 A 的最新提交在 MASTER 上重置后未暫存。 所以我跑了 git 添加。 並致力於MASTER。 似乎分支 A 已與 MASTER 合並。 一切都像我想要的那樣工作,但只是好奇重置是否是這樣工作的?

我跑的東西流..

在分支 A

git add . 
git commit 
git checkout master

在大師

git merge A
warning: Cannot merge binary files: db.sqlite3 (HEAD vs. 
A)
Auto-merging db.sqlite3
CONFLICT (content): Merge conflict in db.sqlite3
Removing blog/templates/blog/comments_listview.html
Auto-merging blog/templates/blog/comments.html
Automatic merge failed; fix conflicts and then commit the result.

將分支 A 推到 github 以防萬一

git reset HEAD~
Unstaged changes after reset:
M       blog/static/blog/base.js
M       blog/templates/blog/comments_listview.html
M       blog/templates/blog/comments.html
M       db.sqlite3


git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified:       blog/static/blog/base.js
modified:       blog/templates/blog/comments_listview.html
modified:       blog/templates/blog/comments.html
modified:       db.sqlite3

git add .
git commit 

現在 MASTER 似乎與分支 A 合並了? 我確實必須暫存修改后的文件並提交。 與分支 A 的合並沖突中唯一的沖突是文件 'db.sqlite3'。 這並沒有與 MASTER “合並”。

git 是否會在 master 上重置 HEAD~ 自動合並分支合並沖突?

不。

似乎分支 A 已與 MASTER 合並

它沒有。

當分支 A 僅包含新文件的添加時,您可能按照您描述的順序意外得到了您想要的結果:即您沒有更新任何文件,或更新文件。 如果是這種情況,它會意外工作,因為嘗試合並會將新文件帶入您的文件系統,並git add. 會將其添加到您創建的新提交中。

因此,現在您會看到 master 上的最新提交將包含您重置之前 master 中的最新提交,並添加新文件。 所以從最終的角度來看,正確的文件在 repo 中,但是最后一次提交被更改以實現這個 state。

暫無
暫無

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

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