2

I use git on a regular basis for collaboration with other people. When we work together on a shared repository, I'd like to be able to view the changes performed by others which happened between my last commit and the current master branch (or the current HEAD).

Until now I'm using the following workflow:

git fetch         # download everything
git merge         # since I'm a trusting person ;)
git logadog       # my git-alias for `git log --all --decorate --oneline --graph`
                  # manually look into how many commits were performed since my last commit
git diff HEAD~3   # if 3 commits were performed since then

Alternatively, I could also use git diff c0ffee (if my last commit was c0ffee).

Although that works, I'd prefer something simpler, like git diff COMPARE_HEAD_WITH_THE_LAST_COMMIT_FROM_MY_USER, but I'm unsure how that would work.

I'm also using the awesome vim-plugin fugitive by Tim Pope and if it would be possible to do this using the :Gdiffsplit HEAD~THE_STUFF_FROM_ABOVE-syntax that would be amazing.

2 Answers 2

2

This is not a very 'git like' way to approach the problem. Normally you would just keep a branch which pointed to your last commit.

However to answer the question, try the following helper function. This is not going to be very efficient, I probably need to user some lower level commands.

my_last_commit(){
        local ME="$(git config user.name)"
        git log --format='%h%n' --author="$ME" -1
}

Then you can do git diff $(my_last_commit)..HEAD (omit HEAD if you like as it is the default) or git logadog $(my_last_commit)^..

2

Don't be such a trusting person. ;-)

Sorry, sorry. Speaking more seriously -- the moment just before you merge is the perfect time to inspect what's changed between your work and your peers'. If you run it before merging, this will show you what's about to change when you merge:

git fetch
git diff ...@{upstream}

In fact, in my own workflow, I've got a "whatsnew" alias for git log ..@{upstream}.

If you'd rather merge first and ask questions later, you could create a temporary branch as a placemarker:

git fetch
git branch -c my_last_commit    # or use -C to overwrite if it already exists
git merge
git diff my_last_commit...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .