我和同事在Git中遇到了这种情况,其中两次提交之间文件丢失,但是我们看不到任何“删除模式100644路径/目标/文件”输出。根据我对Git的了解,我不知道这是怎么可能的。
此处是简化的跟踪信息。让我知道是否有任何进一步的输出有助于调查,我会很乐意附加。
我们在一个分支中找到了2个连续的提交:
git log --oneline
给出:
请注意1423249
和341c603
。现在,我将检查所有这些提交,以显示上一个提交341c603
中存在一个示例文件(还有更多),而下一个提交1423249
中却没有。
➜ git checkout 341c603
Note: checking out '341c603'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b <new-branch-name>
HEAD is now at 341c603 v0.1.230
➜ git log --stat --summary -- app/components/BreadcrumbNav/index.js
commit f88f71e4bec82a004626d2e1326bb1a1544675b3
Author: panguoliang <panguoliang@dae.org>
Date: Wed May 8 13:31:05 2019 +0800
ADD fiat module
app/components/BreadcrumbNav/index.js | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
create mode 100644 app/components/BreadcrumbNav/index.js
➜ ls -l app/components/BreadcrumbNav/index.js
-rw-r--r-- 1 wang.boyang staff 888 May 10 10:10 app/components/BreadcrumbNav/index.js
它在341c603
中。它是在较早的提交中创建的。现在移至1423249
➜ git checkout 1423249
Previous HEAD position was 341c603 v0.1.230
HEAD is now at 1423249 fix websocket, subscribe to current symbol
➜ git log --stat --summary -- ./app/components/BreadcrumbNav/index.js
(empty output)
➜ ls -l app/components/BreadcrumbNav/index.js
ls: app/components/BreadcrumbNav/index.js: No such file or directory
它不在那里!那么,1423249
中有哪些变化?丢失的文件app/components/BreadcrumbNav/index.js
在1423249
中被删除了吗?
➜ git show --stat 1423249
commit 1423249134941968692d2094c64369017838d393 (HEAD)
Author: Wang Boyang <boyang@dae.org>
Date: Thu May 9 12:59:59 2019 +0800
fix websocket, subscribe to current symbol
.eslintrc.js | 2 ++
.prettierrc | 14 ++++++---
app/containers/BarBox/actions.js | 24 ++++++--------
app/containers/BarBox/constants.js | 8 ++---
app/containers/BarBox/index.js | 22 ++++++-------
app/containers/BarBox/reducer.js | 18 ++++-------
app/containers/BarBox/saga.js | 20 ++++++------
app/containers/BarBox/selectors.js | 5 ++-
app/containers/BarBox/styles.js | 5 ++-
app/containers/TradePage/index.js | 116 ++++++++++++++++++++++++++++----------------------------------------
10 files changed, 102 insertions(+), 132 deletions(-)
与丢失的文件app/components/BreadcrumbNav/index.js
绝对没有任何变化。那么,发生了什么事?
以下是git log --graph
的简化输出:
* commit 47750dc0059d503dcd73de767fe9a1914070b6b9
|\ Merge: d1a0f6e 2115249
| | Author: justinji <justin5562587@gmail.com>
| | Date: Thu May 9 17:40:01 2019 +0800
| |
| | resolve conflicts
| |
| * commit 2d8835e30a9a27f9eec687de573e4a77e66ed69a
| |\ Merge: 324857a 341c603
| | | Author: Wang Boyang <boyang@dae.org>
| | | Date: Thu May 9 13:06:22 2019 +0800
| | |
| | | Merge remote-tracking branch 'origin/test' into test
| | |
| | * commit 341c60334919930ee5f731cae3660c80aefb2ca1
| | | Author: panguoliang <panguoliang@dae.org>
| | | Date: Thu May 9 12:03:01 2019 +0800
| | |
| | | v0.1.230
| | |
| | |
| | * commit 66eaf470248a01b6d7861f1b319335255363195c
| | |\ Merge: 5ec1650 63e528b
| | | | Author: panguoliang <panguoliang@dae.org>
| | | | Date: Thu May 9 12:00:48 2019 +0800
| | | |
| | | | lint
| | | |
| | * | commit 9f8b93645851d98b1ab08264de8700a0e0dff47c
| | | | Author: panguoliang <panguoliang@dae.org>
| | | | Date: Thu May 9 11:58:41 2019 +0800
| | | |
| | | | ADD Fiat deposit
| | | |
| | | |
| * | | commit 1423249134941968692d2094c64369017838d393
| | | | Author: Wang Boyang <boyang@dae.org>
| | | | Date: Thu May 9 12:59:59 2019 +0800
| | | |
| | | | fix websocket, subscribe to current symbol
| | | |
| * | | commit 6d2c1073689140b75758d0e008af183340f1842b
| |\ \ \ Merge: f730698 63e528b
| | | |/ Author: Wang Boyang <boyang@dae.org>
| | |/| Date: Thu May 9 10:39:23 2019 +0800
| | | |
| | | | Merge remote-tracking branch 'origin/test' into test
| | | |
发现:在合并提交2d8835e30a9a27f9eec687de573e4a77e66ed69a
中(及之后),文件丢失。猫文件输出:
➜ git cat-file commit 2d8835e30a9a27f9eec687de573e4a77e66ed69a
tree a46f997a76ff403d1ec0567913722787d72bf9f6
parent 324857aa9a26852a2c5699650366ac7797a85ac2
parent 341c60334919930ee5f731cae3660c80aefb2ca1
author Wang Boyang <boyang@dae.org> 1557378382 +0800
committer Wang Boyang <boyang@dae.org> 1557378382 +0800
Merge remote-tracking branch 'origin/test' into test
工具difflame给出以下输出:
➜ ~/Projects/difflame.py 341c603 2d8835e30a9a27f9eec687de573e4a77e66ed69a -- app/components/BreadcrumbNav/index.js
Processing line 48/48
diff --git a/app/components/BreadcrumbNav/index.js b/app/components/BreadcrumbNav/index.js
deleted file mode 100644
index bf18d9d..0000000
--- a/app/components/BreadcrumbNav/index.js
+++ /dev/null
@@ -1,41 +0,0 @@
341c603: v0.1.230
-341c603 (panguoliang 2019-05-09 12:03:01 1 ) /**
-341c603 (panguoliang 2019-05-09 12:03:01 2 ) *
-341c603 (panguoliang 2019-05-09 12:03:01 3 ) * BreadcrumbNav
-341c603 (panguoliang 2019-05-09 12:03:01 4 ) *
-341c603 (panguoliang 2019-05-09 12:03:01 5 ) */
有什么办法找出为什么以这种方式完成合并(即删除文件),以便将来可以避免吗?
答案 0 :(得分:3)
如果修订版本是一个接一个的(看不到...。由于您未指定--graph,它们可能位于两个单独的分支上),那么git show --name-status 1423249
应该将文件显示为已删除
PS,因为这些修订实际上位于两个单独的分支上,这意味着在两个修订的任何祖先中都可能发生了可能删除...或者没有真正的删除参与。这取决于2个分支的历史记录(共同祖先可能缺少这两个文件,其中一个分支仍然缺少它们,它们被添加到了另一个分支上。...在这种情况下,不涉及删除)。>
答案 1 :(得分:0)
所有评论和答案都非常有用。我终于找到了原因。
首先,就像提到的@meagar一样,文件删除仅由不在提交快照中的文件blob表示。事实证明,文件在合并过程中会消失。
对于任何理智的合并工具,当面对2个父级时,一个添加文件而另一个不添加文件时,它将提示并可能添加文件,或显示诸如modified in XXXX but deleted in XXX
之类的冲突。
这不是。因为我误会了以下2:
git merge -s recursive -X ours
git merge -s ours
后者只会忽略其他父母。因此,那里的变化已经消失了。从那时起,所有操作均无法正常进行,并且文件删除错误地保留了