How do I see which commits change a certain file?

Asked

Viewed 5,937 times

21

I implemented a new functionality for my program in an Func1.cpp file, in the branch Func1. Then I created another feature - in the file Func2.cpp -, but I forgot to create in a branch separate Func2. Now, I would like to separate a branch for each feature.

For that, I need to know which commits change the Func1.cpp file and which ones change Func2.cpp. So I can make one rebase --interactive to then separate the branches. I tried to git show <SHA1>, but it shows me information of diff that I don’t need.

Question: How can I find out which commits change which files?

3 answers

16


git log <arquivo>

To make git understand and follow the file even when renamed:

git log --follow <arquivo>
  • The flag --follow must be used before <arquivo>?

  • @Victorhugo Yes! Good observation.

  • 2

    if you are in a branch and want to check changes in another branch you can use git log --follow outro_branch -- <arquivo>.

  • @Brunocoimbra What does this mean --? I’ve used it before to reset modifications to a file: git checkout -- <arquivo>.

  • 1

    @Victorhugo -- in the parameter --follow It has no special sense, it’s just a convention. Usually simple options (one letter) are accompanied by a dash, and complete options (whole words) of two strokes (case of --follow). Already the isolated use of --in the git checkout is a way of telling git that you are referring to a file (not an eventual branch).

  • 2

    the -- is used to indicate that command line options are finished. like git accepts options in formats -h, --help, nome_do_branch and nome_do_arquivo it is necessary to somehow differentiate the last 2 formats.

Show 1 more comment

2

I recommend using an alias in . gitconfig to query this type of information. Put it in your ~/.gitconfig, in the aliases section:

[alias]
    ll = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --numstat

Ready, now git ll will give a report of each commit with the list of files changed by it, similar to:

afe7f7c first commit [Elias]
2       0       src/main.py
11      0       src/dataset.py

f732435 adicionado notebook [Elias]
100     0       testes.ipynb

1

Instead of git show try git log <nome do arquivo>.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.