1

I got an email today saying:

if you did a git pull and included git hash X123 and ran tests, this could have corrupted your machine. You'll need to flush it and start again. If however you pulled before this, or after we applied the patch - then you're fine.

Assumptions:

  • you have a stale repository (this is prior to running git commit)
  • I'm looking for something more sophisticated than trawling through git log results and seeing if I can see the hash

My question is: What is the git command to tell if my repo is currently before or after a particular commit?

Edit:

This is different to asking which branches contain a particular commit. I'm trying to see if my local stale repository contains a commit. (or that it definitely doesn't).

hawkeye
  • 34,745
  • 30
  • 150
  • 304
  • possible duplicate of [How to list branches that contain a given commit?](http://stackoverflow.com/questions/1419623/how-to-list-branches-that-contain-a-given-commit) – harald Apr 27 '15 at 12:10
  • In what way is this different from the contains method? If you want a simple yes/no, you can do `git branch --contains `. – musiKk Apr 27 '15 at 12:28
  • There is no total order for commits, so your repository as a whole cannot be before or after a given commit. A particular branch head may be before or after a commit, depending on whether or not you can reach the commit from the branch head. – chepner Apr 27 '15 at 14:24

1 Answers1

0

I'm looking for something more sophisticated than trawling through git log results and seeing if I can see the hash

How about grepping for the commit hash?

tim@tim-N53SN:~/git/project$ git log --graph --decorate --branches --pretty="oneline" --abbrev-commit
* e2e42a2 (HEAD, origin/master, origin/HEAD, master) Create new User in Splash (if first launch) instead of MyIDSActivity
* 7466154 Added SplashActivity that checks if it's the first start
* 1f0ba11 Replace hardcoded IDs in MyIDS with real data
* 26ee0b9 Changed actionbar and chat bubble colors

tim@tim-N53SN:~/git/project$ git log | grep e2e42a2
commit e2e42a237248da66bbc16482ab1557d0f404532c

grep finds a result because current repo state io after the specified commit

tim@tim-N53SN:~/git/project$ git checkout HEAD^^
tim@tim-N53SN:~/git/project$ git log --graph --decorate --branches --pretty="oneline" --abbrev-commit
* e2e42a2 (origin/master, origin/HEAD, master) Create new User in Splash (if first launch) instead of MyIDSActivity
* 7466154 Added SplashActivity that checks if it's the first start
* 1f0ba11 (HEAD) Replace hardcoded IDs in MyIDS with real data
* 26ee0b9 Changed actionbar and chat bubble colors

tim@tim-N53SN:~/git/project$ git log | grep e2e42a2

grep finds nothing because current repo state is before

Tim
  • 41,901
  • 18
  • 127
  • 145