Get a list of changed files and their status for a specific Git commit

筅森魡賤 提交于 2019-12-23 10:25:36

问题


I use the following Git command

git diff-tree --no-commit-id --name-only -r <SHA>

to get a list of changed files.

Unfortunately, the list doesn't specify the type of change for each file: added, modified or deleted ... etc

How may I display a list of changes [type of change, file name] in a given SHA of a specific commit.


回答1:


Use --name-status instead of --name-only

git diff-tree --no-commit-id --name-status -r <SHA>

This will show the filename with a status letter of (extracted from man): Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R), have their type (i.e. regular file, symlink, submodule, ...) changed (T), are Unmerged (U), are Unknown (X), or have had their pairing Broken (B).




回答2:


While Joe's answer points out that you can use the --name-status flag with git diff-tree, you can also use the same flag with git diff instead.

To get the changed files with their status for just a specific commit, you can just use the sha id of that commit with a commit-parent specifier, like so

git diff --name-status <sha>^ <sha>

The revision specifier <sha>^ means the first parent of the commit <sha>, so using that with git diff effectively gives you all the changes that were made between a commit and its parent.

Alternative

You can also use

git diff --name-status <sha>~ <sha>

where <sha>~ also means the first parent of commit <sha>.

Documentation

  • git-diff(1) Manual Page
  • gitrevisions(7) Manual Page



回答3:


Thanks to hvd's comment on stdcall's answer,

Your original answer, which included the git whatchanged SHA-1 form, was almost right: add the -1 option to get only that specific commit.

here is the solution for those who are interested:

git whatchanged <SHA> -1

Another solution is:

git diff-tree --no-commit-id -r <SHA>



回答4:


Use

git whatchanged 

to see the last commit




回答5:


git checkout <commit>
git whatchanged -1


来源:https://stackoverflow.com/questions/24803627/get-a-list-of-changed-files-and-their-status-for-a-specific-git-commit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!