tags:

views:

417

answers:

1

Does anyone know of a git plumbing (definitely not porcelain) means of determining whether:

  • there are edits in the repo since the last commit, and
  • whether local HEAD is ahead of origin/HEAD

I am looking to determine this programmatically, hence the desire to not solve this with porcelain and various sed-fu.

+3  A: 

In porcelain command, a: $ git diff HEAD

gives you the changes since the last commit (what you would be committing if you run "git commit -a").

A possible equivalent in plumbing command would be:

$ git ls-files -m

for listing all modified (working directory or index) files


If you create your repository by cloning someone else's repository, the remote "master" branch is copied to a local branch named "origin". You get your own "master" branch which is not tied to the remote repository.

There is always a current head, known as HEAD. (This is actually a symbolic link, .git/HEAD, to a file like refs/heads/master.)

run "git status" and analyze the output:

# On branch master
# Your branch is ahead of 'origin/master' by 11 commits.
#

More details in the SO question "Why is Git telling me “Your branch is ahead of ‘origin/master’ by 11 commits.” and how do I get it to stop?"

Possible equivalent in plumbing command:

* git-for-each-ref

for listing all commits, but requires analyzing the output as well...

Again, git ls-files could be used to produced the same result than a git status.

git ls-files --exclude-per-directory=.gitignore --exclude-from=.git/info/exclude \
                    --others \
                    --modified \
                    -t
VonC
That's great. Thanks very much.
Paul Beckingham
"git ls-files --exclude-standard ..." would be a bit simpler.
Jakub Narębski