为什么 git 在合并后丢失了日志中的提交?
Why does git lose a commit from log after merge?
我正在尝试将开发分支合并到主分支中。但它似乎撤消了在 master 中所做的提交,以至于特定提交不再出现在文件的 git log
.
中
当我在 master 分支上时,我可以在 7 月 14 日看到提交 2d1b9af
c:\src>git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
c:\src>git log server\Fitnesse\FitNesseRoot\APITest\content.txt
commit 88a68b11b273b98531ae686b85b5733b86706bda
Author: charles
Date: Fri Jul 15 00:56:44 2016 +0000
XX-338 Add IsDeleted to Place table
commit 2d1b9afdabd7fbbf970d697bd0c15957a8fd288a
Author: charles
Date: Thu Jul 14 23:15:28 2016 +0000
fix FitNesse test which are broken by renaming
commit f1616fed48bb15c1c120cfe016e571f49aae6244
Author: charles
Date: Tue Jun 21 11:04:53 2016 +1200
modify fitNesse Test for new API changes.
然后我合并到我的大分支。
c:\src>git merge origin/myLargeBranch
Removing server/Database/355_UnitTest.sql
Merge made by the 'recursive' strategy.
.../packages.config | 2 +-
.../Utilities/Extensions/StringExtensions.cs | 10 +
.../Utilities/Throttle.cs | 45 ++++
[ ... etc ]
.../FitNesseRoot/APITest/content.txt | 37 +--
128 files changed, 3705 insertions(+), 481 deletions(-)
create mode 100644 [ ... ]
c:\src>git status
On branch master
Your branch is ahead of 'origin/master' by 32 commits.
(use "git push" to publish your local commits)
nothing to commit, working directory clean
我在这里注意到它改变了我正在查看的文件。自从我上了分支以来,我实际上并没有修改过这个文件。这可能与我的问题有关,但这并不是我要问的具体问题。
现在对我来说重要的是,他从 7 月 14 日开始提交的内容不再出现在我的日志中:
c:\src>git log server\Fitnesse\FitNesseRoot\APITest\content.txt
commit f1616fed48bb15c1c120cfe016e571f49aae6244
Author: charles
Date: Tue Jun 21 11:04:53 2016 +1200
modify fitNesse Test for new API changes.
commit 16b7beb9d1045f5fe7354c0fdbe637a49bb48ce0
Author: charles
Date: Tue May 10 10:54:13 2016 +1200
所以我是一个小,担心最后会得到错误的代码。这是一个位的烦恼。
但我更担心 git 现在没有在日志中显示曾经进行过更改。
我错过了什么?
更新 在@tim-biegeleisen 发表评论后,我追踪到了实际的提交,但仍然很困惑。
罪魁祸首似乎是从 master 合并到我的开发分支:
c:\src>git show b5637f9
commit b5637f9a65e415f1b415fad99c9e7a4e6b46ab1a
Merge: cb8ed90 6b5c0e1
Author: GregH <GregH@GREGH-LT001>
Date: Tue Jul 26 04:25:40 2016 +0000
Merge from master
[ ... ]
cb8...是我的分支:
c:\src>git checkout cb8ed90
Previous HEAD position was 6b5c0e1... PR 93: Merge DeletePlace to master
HEAD is now at cb8ed90... Added tests for apple messages
c:\src>git log server\Fitnesse\FitNesseRoot\APITest\content.txt
commit f1616fed48bb15c1c120cfe016e571f49aae6244
Author: charles
Date: Tue Jun 21 11:04:53 2016 +1200
6b5...是大师
c:\src>git checkout 6b5c0e1
Previous HEAD position was cb8ed90... Added tests for apple messages
HEAD is now at 6b5c0e1... PR 93: Merge DeletePlace to master
c:\src>git log server\Fitnesse\FitNesseRoot\APITest\content.txt
commit 88a68b11b273b98531ae686b85b5733b86706bda
Author: charles
Date: Fri Jul 15 00:56:44 2016 +0000
合并后,我丢失了 7 月 14 日至 15 日的提交。
c:\src>git checkout b5637f9
Previous HEAD position was 6b5c0e1... PR 93: Merge DeletePlace to master
HEAD is now at b5637f9... Merge from master
c:\src>git log server\Fitnesse\FitNesseRoot\APITest\content.txt
commit f1616fed48bb15c1c120cfe016e571f49aae6244
Author: charles
Date: Tue Jun 21 11:04:53 2016 +1200
**更新:**由 VonC 建议,git log --all
显示提交仍在历史记录中。
没有--all
,如上,显示最新更新6月21日
git 日志 server\Fitnesse\FitNesseRoot\APITest\content.txt
(没有必要重复它)。
但是和 --all
他们在那里:
c:\src>git log --all server\Fitnesse\FitNesseRoot\APITest\content.txt
commit 88a68b11b273b98531ae686b85b5733b86706bda
Author: charles
Date: Fri Jul 15 00:56:44 2016 +0000
XX-338 Add IsDeleted to Place table
commit 2d1b9afdabd7fbbf970d697bd0c15957a8fd288a
Author: charles
Date: Thu Jul 14 23:15:28 2016 +0000
fix FitNesse test which are broken by renaming
commit f1616fed48bb15c1c120cfe016e571f49aae6244
Author: charles
Date: Tue Jun 21 11:04:53 2016 +1200
modify fitNesse Test for new API changes.
那么为什么它们在合并期间被撤消了?
您从 git log
获得的输出实际上相当棘手。您可以触发许多陷阱。在这种情况下,您遇到的问题称为“历史简化”。引用自 the documentation:
Sometimes you are only interested in parts of the history, for example the commits modifying a particular <path>. But there are two parts of History Simplification, one part is selecting the commits and the other is how to do it, as there are various strategies to simplify the history.
The following options select the commits to be shown:
<paths>
Commits modifying the given <paths> are selected.
--simplify-by-decoration
Commits that are referred by some branch or tag are selected.
Note that extra commits can be shown to give a meaningful history.
The following options affect the way the simplification is performed:
Default mode
Simplifies the history to the simplest history explaining the final state of the tree. Simplest because it prunes some side branches if the end result is the same (i.e. merging branches with the same content)
--full-history
Same as the default mode, but does not prune some history.
[snip]
在合并之前,Git 简化历史记录,无需查看合并路径。
合并后,Git 简化历史记录,同时查看合并的路径(或者更确切地说,“两条路径”)。由于您使用的是默认模式,这允许 Git “修剪一些侧枝”,如文档所述(无需详细说明 哪些 侧枝正在被删除修剪,尽管本节后面有更多使用单词 TREESAME
的内容:没有说明的事实是 TREESAME
在剥离除列出的 中的文件之外的每个文件后进行测试)。
如果您添加 --full-history
,您应该会看到您的提交 return。
请注意,如果您未指定某些路径,历史简化不会打开,除非您添加一些特定的简化选项(在我截取的部分中) .
我正在尝试将开发分支合并到主分支中。但它似乎撤消了在 master 中所做的提交,以至于特定提交不再出现在文件的 git log
.
当我在 master 分支上时,我可以在 7 月 14 日看到提交 2d1b9af
c:\src>git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
c:\src>git log server\Fitnesse\FitNesseRoot\APITest\content.txt
commit 88a68b11b273b98531ae686b85b5733b86706bda
Author: charles
Date: Fri Jul 15 00:56:44 2016 +0000
XX-338 Add IsDeleted to Place table
commit 2d1b9afdabd7fbbf970d697bd0c15957a8fd288a
Author: charles
Date: Thu Jul 14 23:15:28 2016 +0000
fix FitNesse test which are broken by renaming
commit f1616fed48bb15c1c120cfe016e571f49aae6244
Author: charles
Date: Tue Jun 21 11:04:53 2016 +1200
modify fitNesse Test for new API changes.
然后我合并到我的大分支。
c:\src>git merge origin/myLargeBranch
Removing server/Database/355_UnitTest.sql
Merge made by the 'recursive' strategy.
.../packages.config | 2 +-
.../Utilities/Extensions/StringExtensions.cs | 10 +
.../Utilities/Throttle.cs | 45 ++++
[ ... etc ]
.../FitNesseRoot/APITest/content.txt | 37 +--
128 files changed, 3705 insertions(+), 481 deletions(-)
create mode 100644 [ ... ]
c:\src>git status
On branch master
Your branch is ahead of 'origin/master' by 32 commits.
(use "git push" to publish your local commits)
nothing to commit, working directory clean
我在这里注意到它改变了我正在查看的文件。自从我上了分支以来,我实际上并没有修改过这个文件。这可能与我的问题有关,但这并不是我要问的具体问题。
现在对我来说重要的是,他从 7 月 14 日开始提交的内容不再出现在我的日志中:
c:\src>git log server\Fitnesse\FitNesseRoot\APITest\content.txt
commit f1616fed48bb15c1c120cfe016e571f49aae6244
Author: charles
Date: Tue Jun 21 11:04:53 2016 +1200
modify fitNesse Test for new API changes.
commit 16b7beb9d1045f5fe7354c0fdbe637a49bb48ce0
Author: charles
Date: Tue May 10 10:54:13 2016 +1200
所以我是一个小,担心最后会得到错误的代码。这是一个位的烦恼。
但我更担心 git 现在没有在日志中显示曾经进行过更改。
我错过了什么?
更新 在@tim-biegeleisen 发表评论后,我追踪到了实际的提交,但仍然很困惑。
罪魁祸首似乎是从 master 合并到我的开发分支:
c:\src>git show b5637f9
commit b5637f9a65e415f1b415fad99c9e7a4e6b46ab1a
Merge: cb8ed90 6b5c0e1
Author: GregH <GregH@GREGH-LT001>
Date: Tue Jul 26 04:25:40 2016 +0000
Merge from master
[ ... ]
cb8...是我的分支:
c:\src>git checkout cb8ed90
Previous HEAD position was 6b5c0e1... PR 93: Merge DeletePlace to master
HEAD is now at cb8ed90... Added tests for apple messages
c:\src>git log server\Fitnesse\FitNesseRoot\APITest\content.txt
commit f1616fed48bb15c1c120cfe016e571f49aae6244
Author: charles
Date: Tue Jun 21 11:04:53 2016 +1200
6b5...是大师
c:\src>git checkout 6b5c0e1
Previous HEAD position was cb8ed90... Added tests for apple messages
HEAD is now at 6b5c0e1... PR 93: Merge DeletePlace to master
c:\src>git log server\Fitnesse\FitNesseRoot\APITest\content.txt
commit 88a68b11b273b98531ae686b85b5733b86706bda
Author: charles
Date: Fri Jul 15 00:56:44 2016 +0000
合并后,我丢失了 7 月 14 日至 15 日的提交。
c:\src>git checkout b5637f9
Previous HEAD position was 6b5c0e1... PR 93: Merge DeletePlace to master
HEAD is now at b5637f9... Merge from master
c:\src>git log server\Fitnesse\FitNesseRoot\APITest\content.txt
commit f1616fed48bb15c1c120cfe016e571f49aae6244
Author: charles
Date: Tue Jun 21 11:04:53 2016 +1200
**更新:**由 VonC 建议,git log --all
显示提交仍在历史记录中。
没有--all
,如上,显示最新更新6月21日
git 日志 server\Fitnesse\FitNesseRoot\APITest\content.txt
(没有必要重复它)。
但是和 --all
他们在那里:
c:\src>git log --all server\Fitnesse\FitNesseRoot\APITest\content.txt
commit 88a68b11b273b98531ae686b85b5733b86706bda
Author: charles
Date: Fri Jul 15 00:56:44 2016 +0000
XX-338 Add IsDeleted to Place table
commit 2d1b9afdabd7fbbf970d697bd0c15957a8fd288a
Author: charles
Date: Thu Jul 14 23:15:28 2016 +0000
fix FitNesse test which are broken by renaming
commit f1616fed48bb15c1c120cfe016e571f49aae6244
Author: charles
Date: Tue Jun 21 11:04:53 2016 +1200
modify fitNesse Test for new API changes.
那么为什么它们在合并期间被撤消了?
您从 git log
获得的输出实际上相当棘手。您可以触发许多陷阱。在这种情况下,您遇到的问题称为“历史简化”。引用自 the documentation:
Sometimes you are only interested in parts of the history, for example the commits modifying a particular <path>. But there are two parts of History Simplification, one part is selecting the commits and the other is how to do it, as there are various strategies to simplify the history.
The following options select the commits to be shown:
<paths>
Commits modifying the given <paths> are selected.
--simplify-by-decoration
Commits that are referred by some branch or tag are selected.
Note that extra commits can be shown to give a meaningful history.
The following options affect the way the simplification is performed:
Default mode
Simplifies the history to the simplest history explaining the final state of the tree. Simplest because it prunes some side branches if the end result is the same (i.e. merging branches with the same content)
--full-history
Same as the default mode, but does not prune some history.
[snip]
在合并之前,Git 简化历史记录,无需查看合并路径。
合并后,Git 简化历史记录,同时查看合并的路径(或者更确切地说,“两条路径”)。由于您使用的是默认模式,这允许 Git “修剪一些侧枝”,如文档所述(无需详细说明 哪些 侧枝正在被删除修剪,尽管本节后面有更多使用单词 TREESAME
的内容:没有说明的事实是 TREESAME
在剥离除列出的
如果您添加 --full-history
,您应该会看到您的提交 return。
请注意,如果您未指定某些路径,历史简化不会打开,除非您添加一些特定的简化选项(在我截取的部分中) .