简体   繁体   English

git diff --name-only 显示未更改的文件

[英]git diff --name-only shows unchanged files

Edit: It doesn't, I explained below what made me think so.编辑:它没有,我在下面解释了是什么让我这么认为。

I am working on a feature branch and the output of the command git diff develop --name-only shows a large list of files:我正在处理一个功能分支,命令git diff develop --name-only的输出显示了一个大文件列表:

...

path/to/some/unchangedFile.cpp

...

and the command git diff develop -- path/to/some/unchangedFile.cpp shows no output and the files are identical in both commits.并且命令git diff develop -- path/to/some/unchangedFile.cpp显示输出,并且两次提交中的文件都相同。

What could cause such issue?什么会导致这样的问题?

So the problem for me was that:所以我的问题是:

a.一种。 The printed paths were relative to the repository's root and are not absolute or relative to the working directory.打印的路径相对于存储库的根目录,而不是绝对的或相对于工作目录的。 I personally think it is a bad implementation because most of the time when I use --name-only I will want to perform a task on the files that were changed and I shouldn't need to "trim" the path myself我个人认为这是一个糟糕的实现,因为在大多数情况下,当我使用 --name-only 时,我想对已更改的文件执行任务,而我不需要自己“修剪”路径

b.git-diff doesn't print anything when the file argument doesn't exist on both commits.当文件参数在两次提交中都不存在时, git-diff 不会打印任何内容。 That is counter intuitive in my opinion.在我看来,这是违反直觉的。 When no output is shown I assume the file exists and is identical in both commits.当没有显示输出时,我假设该文件存在并且在两次提交中都是相同的。 I think a warning message is appropriate in this case.我认为在这种情况下警告消息是合适的。

You can list the (tracked) files changed in your feature branch since it was created like so :您可以列出功能分支中更改的(跟踪)文件,因为它是这样创建的:

$ git --no-pager diff --name-only FETCH_HEAD $(git merge-base FETCH_HEAD develop)

$(git merge-base FETCH_HEAD develop) returns the last commit on develop before creating the current branch. $(git merge-base FETCH_HEAD develop)在创建当前分支之前返回$(git merge-base FETCH_HEAD develop)的最后一次提交。 Then diff compare the current head to this commit.然后diff将当前头部与此提交进行比较。

You can also see files changed since the last commit您还可以看到自上次提交以来更改的文件

$ git --no-pager diff --name-only FETCH_HEAD~1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM