How to know which was the last commit to move in the same file as my commit?

14

I got to read the question How do I see which commits change a certain file? It's almost what I need in case I want to know if it's possible for me to get the last commit that changed any file I've changed.

Is this possible? Or do I have to give git log <arquivo> to all the files I've changed and get the most recent commit?

    
asked by anonymous 30.09.2014 / 15:57

5 answers

3

From the root directory of the repository:

git diff --name-only <rev>^! | xargs git log <rev>^ -1 --

Where <rev> is the SHA-1 (or piece of SHA-1) of your commit that contains the files you have modified.

This command does:

  • git diff --name-only <rev>^! : Creates a listing of modified files in the commit.
  • | xargs : passes the listing into a single space-separated string for the following command.
  • git log <rev>^ -1 -- : Generates the log before commit (so ^ ), with a single entry (hence -1 ) and based on the files of the listing passed to the end of the command.

The git log command when it receives multiple files as an argument will log commits where any of them appear only. So the first one that pops up, is what you want.

Note that if your files have namespace or relative path space, the command probably needs to be changed.

    
12.11.2014 / 08:04
6

Friend you can use

git log <arquivo>

and to make git understand and follow the file.

git log --follow <arquivo>

You can follow the branch.

git log --follow outro_branch -- <arquivo>

You can see who changed a particular file

git blame filename

But for example. If two developers have made 5 commits to the project, with

  

git shortlog

You will get this output:

/#: git shortlog

Mary (2):
      Fix a bug in the feature
      Fix a serious security hole in our framework

John (3):
      Add the initial code base
      Add a new feature
      Merge branch 'feature'
    
11.11.2014 / 16:59
2

Sempe has the following:

git whatchanged <path>.

The command lists all commits that have moved in the same path that was passed by parameter.

    
12.11.2014 / 13:43
0

You can simply use git log in the main branch folder. You can also filter by users in this case git log --author=Foo

    
11.11.2014 / 17:09
0

I do not know if I understood correctly, but I'll try to answer the following excerpt that I removed from your question. If that's not what you're looking for, try giving examples to try to help.

  

"... in case I want to know if it is possible I get the last commit that changed any file I have changed."?

If you want the last commit you can use:

git log -1

And according to Talles' previous response (referenced in the question), if you want to see the last commit of a specific file :

git log --follow <arquivo>
    
11.11.2014 / 17:35