How do I know the last commit to move the same file as my commit?

Asked

Viewed 3,666 times

15

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

Is that possible? Or do I have to give one git log <arquivo> in all the files I changed and grab the latest commit?

  • guess git Blame <file> can help you.

  • 1

    But if I want in all files modified? Just don’t have to do one by one.

  • Got it, very similar to the details of github right?

  • Yeah, more or less...

  • 1

    By altered you mean a file you’ve already added to Stage but haven’t committed yet?

  • 1

    Or all files modified in the last commit?

  • Already committed, but what was the last commit before the one that touched any of the commited files.

  • The question was not clear and without examples, but by the reply of the staff the topic became quite interesting. If possible improve the quality of the question

Show 3 more comments

5 answers

7

Friend you can use

git log <arquivo>

and to make git understand and follow the file.

git log --follow <arquivo>

You can go through 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 that exit:

/#: 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'
  • Then just follow all the commit files, right? This solution interests me. Is there any way to declare multiple files to follow at once?

  • Wouldn’t it be better to follow the branch then ?

  • It’s just that I think the OP question is about how to verify which commits changed only the files that the developer changed, not all of the branch. This solution pleases me as I can make a script to automatically follow any file I change, for example. Resolve. But if there is any alternative to dispense with this, I would be even happier. BTW +1.

  • I’m not home now if I wouldn’t help you, I’m here for Colonel. If I find a post here

  • I’m seeing here a solution, but just to be clear, when you follow the clear branch you will see only the files changed by the developers, because the logs are made on top of changes, if they don’t occur obviously they won’t appear.

  • With this one you see who changed the file. git Blame filename and this one changes a particular file gitk filename.

  • I will edit my reply with something that can help you more. If it is unnecessary I remove.

  • For further information : https://www.atlassian.com/git/tutorials/git-log/filtering-the-commit-history

Show 3 more comments

4


From the repository root directory:

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

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

This command makes:

  • git diff --name-only <rev>^!: Create a list of the modified files in the commit.
  • | xargs: forwards the listing in a single string separated by spaces to the following command.
  • git log <rev>^ -1 --: Generates the log before your commit (so ^), with a single entry (so -1) and based on the list files passed at the end of the command.

The command git log when you receive multiple files as argument, you will log commits where any of them only appear. So the first one who shows up, is the one you want.

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

2

Sempe has the:

git whatchanged <path>.

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

0

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

0

I do not know if I understand correctly, but I will try to answer the part below that I have taken from your question. If that’s not what you’re looking for, try giving examples to try to help.

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

If you want the last commit can use:

git log -1

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

git log --follow <arquivo>

Browser other questions tagged

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