How can I generate a git diff of what's changed since the last time I pulled?

后端 未结 4 669
失恋的感觉
失恋的感觉 2020-12-07 08:24

I\'d like to script, preferably in rake, the following actions into a single command:

  1. Get the version of my local git repository.
  2. Git pull the latest
4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-07 08:37

    You could do this fairly simply with refspecs.

    git pull origin
    git diff @{1}..
    

    That will give you a diff of the current branch as it existed before and after the pull. Note that if the pull doesn't actually update the current branch, the diff will give you the wrong results. Another option is to explicitly record the current version:

    current=`git rev-parse HEAD`
    git pull origin
    git diff $current..
    

    I personally use an alias that simply shows me a log, in reverse order (i.e. oldest to newest), sans merges, of all the commits since my last pull. I run this every time my pull updates the branch:

    git config --global alias.lcrev 'log --reverse --no-merges --stat @{1}..
    

提交回复
热议问题