14

After pulling from a git server, I'm trying to get a list of all changed files. I don't need any specific parts of code, just a list of files (with some kind of indication as to wether it's been added, removed or changed).

I first looked at using git log, but that appearantly only returns info from the last commit:

git log --name-status --max-count=1 --pretty=format:""

Since this appearantly only gets the changes from the last commit in a pull, I'm trying to find a way to get all the changes (the pull almost always exists out of multiple commits).

Is there any command for this? (I'm interacting with Git from PHP, btw)

Gilles Maes
  • 143
  • 1
  • 1
  • 6

2 Answers2

28

After a pull, ORIG_HEAD refers to where you were before, and HEAD refers to where you are now. So ORIG_HEAD.. means the changes pulled into the current branch. --max-count=1 means just the last commit, not what you want, as you discovered.

You probably want something like git diff --name-status ORIG_HEAD.. which will output a single-character status code and a filename for each file changed, aggregating all the commits together. If you want it broken down by each change, you need something like git log --oneline --name-status ORIG_HEAD..

araqnid
  • 127,052
  • 24
  • 157
  • 134
  • 1
    `git diff --name-status ORIG_HEAD..` worked like a charm, can't say thank you enough! – Gilles Maes Jun 30 '11 at 13:33
  • 2
    `alias gpull='git pull; git diff --name-status ORIG_HEAD..'` Just what I wanted, added this to my .bashrc – tponthieux Feb 18 '13 at 19:52
  • This doesn't work as desired if you have your remote tracking branch tracking a different branch. For example, if I have my branch `topic` tracking `origin/master`. Pull will rebase `topic` onto `origin/master`. To see the delta introduced only on the upstream branch, you can run `git lg @{1}..@{u}`. `@{1}` uses reflogs and is the same as `ORIG_HEAD`. `@{u}` is your upstream branch (remote tracking branch) – void.pointer Jan 25 '18 at 20:51
0

An alternative command is:

git pull --stat 
iblue
  • 29,609
  • 19
  • 89
  • 128
mshiltonj
  • 316
  • 3
  • 14