我遇到了一个问题,git 说提交已 merge ,但是
来自提交的更改不在我的工作树中。为了让事情变得更奇怪,git log --name-status 362dde7
告诉我提交修改了一个文件,但是git log -- path/to/modified/file.java
不显示提交。例如:
确保有问题的提交存在于开发分支和功能分支上。
$ git branch --contains 362dde74f142831c99820b999558a2e8f49f66e8
* dev
feature
列出提交修改的文件。
$ git show --name-status 362dde74f142831c99820b999558a2e8f49f66e8
# commit summary... #
M path/to/modified/file.java
现在,当我反向操作时(列出修改文件的提交),未列出提交。
$ git log path/to/modified/file.java
# Commit 362dde7 isn't listed here
如果我切换到功能分支并遵循相同的步骤,一切都会按预期进行。
$ git checkout feature
$ git show --name-status 362dde74f142831c99820b999558a2e8f49f66e8
# commit summary... #
M path/to/modified/file.java
$ git log path/to/modified/file.java
362dde7 Commit summary
基本上,
dev
和 feature
上都存在相同的提交,但工作树的更改仅在我 check out feature
时才会显示。有没有人知道为什么会这样? 最佳答案
$ git init so19234836
Initialized empty Git repository in /tmp/g/so19234836/.git/
$ cd so19234836/
$ echo "content created" > file
$ git add file
$ git commit -m c1
[master (root-commit) a965818] c1
1 file changed, 1 insertion(+)
create mode 100644 file
$ git checkout -b feature
Switched to a new branch 'feature'
$ echo "feature change"> file
$ git commit -am f1
[feature eaf4121] f1
1 file changed, 1 insertion(+), 1 deletion(-)
$ git checkout master
Switched to branch 'master'
$ git merge -s ours feature
Merge made by the 'ours' strategy.
现在我有类似的 repo 状态:
$ git log file
commit a965818706c47d065b81a994aeb5fc24cd77d001
Author: Anatoly Kupriyanov <kan.izh@gmail.com>
Date: Mon Oct 7 22:44:52 2013 +0100
c1
$ git checkout feature
Switched to branch 'feature'
$ git log file
commit eaf41212872d784d4e4e50e62167072d35b6167f
Author: Anatoly Kupriyanov <kan.izh@gmail.com>
Date: Mon Oct 7 22:49:02 2013 +0100
f1
commit a965818706c47d065b81a994aeb5fc24cd77d001
Author: Anatoly Kupriyanov <kan.izh@gmail.com>
Date: Mon Oct 7 22:44:52 2013 +0100
c1
$ git branch --contains eaf41212872d784d4e4e50e62167072d35b6167f
* feature
master
因此,基本上,如果您从另一个分支进行 merge ,但恢复文件的 merge 提交中的任何更改,则内容不会更改,但 merge 的提交会出现在历史记录中。
关于git - 为什么提交引入的更改没有显示在我的工作树中?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19234836/