![](/img/trans.png)
[英]Git: Is there a way to re-merge two commits on the same branch (FF) to a new branch?
[英]Is there a way to conflict-merge past commits of a same branch?
所以這是交易:
我正在處理一個家庭作業文件。 我checkout
倉庫中的倉庫,並在倉庫中添加了評論。 但是在合並注釋之前,我對部分源代碼進行了更改。 當我合並兩個分支時,我應該使用git checkout --ours
來保存分支A的更改部分和分支B的注釋部分。更糟糕的是,合並后甚至進行了更多更改。
所以它基本上是這樣的
Source code Source code
----------- -----------
Part A -> Part A Change source
----------- -----------
Part B Part B
----------- -----------
Source code
-----------
-> Part A
-----------
Part B Comments
-----------
這應該已經合並成
Source code
-----------
Part A Change source And then More changes
-----------
Part B Comments
-----------
但是它變成了
Source code
-----------
Part A Change source And then more changes
-----------
Part B
-----------
現在,我嘗試通過git merge 6883dbbb
(評論標簽)進行合並沖突,但顯示
Already up to date.
我已經看到了許多建議檢查分支的回復。 但是,我希望部分反轉單個文件。 因為我在初始合並后添加了(並希望保留)更多更改,所以我無法簽出合並點。 對這個問題有什么建議嗎? 謝謝。
| * commit 4a51c9ac25e88f29b57d345ec294413e0969f1b6
| |\ Merge: 98b00f5 688a3db
| | | Author:
| | | Date: Tue May 7 00:51:21 2019 +0900
| | |
| | | complete merge
| | |
| | * commit 688a3dbbbf7dab71703bb3107f0d4451cf85da88
| | | Author:
| | | Date: Sun May 5 03:02:39 2019 +0900
| | |
| | | HW4 report initial finish part 1 & comments
| | |
| * | commit 98b00f5db8844251b13dc98ac5d6314d4fc4180f
| | | Author:
| | | Date: Tue May 7 00:39:35 2019 +0900
| | |
| | | confirm everything works
| | |
| * | commit a89a77a64336dad49d124a2e8470b84764b9660d
| | | Author:
| | | Date: Sun May 5 17:08:26 2019 +0900
| | |
| | | move testcase
| | |
| * | commit 40c4977a813088c910c54002cd9ca56eb880f722
| |/ Author:
| | Date: Sun May 5 17:07:01 2019 +0900
| |
| | fix bubble
| |
實際上 ,您擁有的內容與您合並后的內容相同,然后還原了合並。 也就是說, git
認為分支上的提交是“已解決”的,但是更改被撤消了。 (不同之處在於合並本身取消了更改,而不是以后的提交,但是效果是相同的。)
要解決這種情況,您需要創建新的提交來模仿分支上的提交。 最簡單的方法是使用git rebase -f
。
唯一的麻煩是,您需要確定分支與master
分開的提交(或任何“上游”分支;為了便於討論,我們將其稱為master
)-以及做到這一點的“顯而易見”方法(例如merge-base
)不能按您期望的那樣工作,因為現在可以從master
訪問整個分支。 但是,如果您知道這只是一次提交,那就足夠簡單了:
git checkout branch
git rebase -f HEAD^
現在,您可以再次合並branch
了。
我只是簡單地用注釋手動重新創建提交:
git format-patch 6883dbbb --stdout | patch -p1
git commit -a -m 'Re-applied comments commit'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.