Smile
Smile

Reputation: 31

How to view the content of a moved file submitted for modification

I use the git log --follow command to view the submission history of a file, but I enter the git show <cmmid> <file name> command, which returns nothing

Upvotes: 3

Views: 31

Answers (1)

LeGEC
LeGEC

Reputation: 51780

Two ways :

  • git log can take the -p|--patch option to display the diff of each commit it selects
  • git show also accepts the --follow option
git log --follow -p -- path/to/file.new
# to display only one commit :
git log --follow -p -1 <commitid> -- path/to/file.new

git show --follow <commitid> -- path/to/file.new

You can also provide the name of the file before and after the renaming :

git log -p -- path/to/file.old path/to/file.new

git show <commitid> -- path/to/file.old path/to/file.new

[edit]

If your intention is to review the changes introduced by a specific pull request (if your central repo is a github/azure devops/gitlab/... instance) :

One way to view the same diff, on your local repo, as the one you see in your web GUI is :

git diff master...feature/branch   # 3 dots, not a typo

The "3 dots" notation for git diff is a shortcut to say "from the merge base of both branches" (link to docs).

If you want to view the diff for a specific file, even when that file was renamed during the fork, git diff also understands the --follow option :

git diff --follow master...feature/branch -- path/to/file.new

Upvotes: 1

Related Questions