1

Say I have a git repository where I never commit changes and only use it to read its contents. Every now and then I pull from origin remote to stay up to date with the most recent changes.

Is there a way for me to know which versions I have checked out since I cloned the repository?

Why do I need this?

The problem I have is that I pull from the remote rarely and the project evolves quickly, so I would like to keep track of the commits that I have used (i.e. checked out) in the past, in case I want to revert my working directory to a state where I know it was working for me. Remember, I am only interested in the commits that I have actually checked out.

Update: It looks like I can do this with tags (tag before I pull), although I can't figure out how to get git to only list my tags. Still, I was wondering if git would already keep track for me of the commits I have checked out.

Community
  • 1
  • 1
Amelio Vazquez-Reina
  • 91,494
  • 132
  • 359
  • 564

7 Answers7

6

You can use the reflog for this but only up to its limit (it gets cleaned out sometimes). For instance - a quick test on a local clone of msysGit:

$ git log -g --oneline --abbrev-commit --grep-reflog "pull:"
53e28dd HEAD@{7}: pull: Fast-forward
947ccf6 HEAD@{9}: pull: Fast-forward
6bf64a4 HEAD@{10}: pull: Fast-forward
20344ae HEAD@{15}: pull: Merge made by the 'recursive' strategy.
31dd6ff HEAD@{36}: pull: Fast-forward
b4546cc HEAD@{37}: pull: Fast-forward
fd6f8d0 HEAD@{38}: pull: Fast-forward
4fc3780 HEAD@{41}: pull: Fast-forward

This shows the commit id's that I happened to do 'pull' for on this system over the last few months. git log -g is the more detailed version of git reflog.

If you just do a git log -g you might see more appropriate things to select for in the set provided. Checkouts might be useful to you.

patthoyts
  • 32,320
  • 3
  • 62
  • 93
1

The references @{-<n>} (e.g. @{-1}, @{-2} etc.) will tell you the references checked out before the current checkout. You might be able to parse a list of those.

cmbuckley
  • 40,217
  • 9
  • 77
  • 91
0

Does git status or git log not give you what you're looking for?

Matt Ball
  • 354,903
  • 100
  • 647
  • 710
  • Wouldn't `git log` show me the full list of commits? (i.e. not necessarily the ones I have checked out in my working directory). – Amelio Vazquez-Reina Jan 09 '13 at 23:13
  • Sort of, yes. But with git, if your working directory is clean, all commits in the history of the repo is present. That's just how git works. That said, you seem to be confused. With git, you don't "check out commits," you check out a branch. – Matt Ball Jan 09 '13 at 23:17
  • But the branches evolve over time, so I need commits. The problem I have is that I pull the project rarely, but the project evolves quickly, and I would like to keep track of **the commits that I have used (i.e. checked out) in the past**, in case I want to revert my working directory to a state where I know the code in the working directory was working for me. – Amelio Vazquez-Reina Jan 09 '13 at 23:22
  • 1
    Sounds like you should tag every time you pull. http://git-scm.com/book/en/Git-Basics-Tagging – Matt Ball Jan 09 '13 at 23:25
  • I was guessing tagging would help, although I was wondering if git would keep track of this for me. Is there a way to see the full list of my tags, right next to their timestamps? (that's all I would need) – Amelio Vazquez-Reina Jan 09 '13 at 23:26
  • 1
    To make your workflow simpler, consider setting up a post-merge hook (locally, of course) to automatically tag after you pull. http://stackoverflow.com/questions/4185400/is-there-any-git-hook-for-pull – Matt Ball Jan 09 '13 at 23:30
0

Does git logs --author switch do what you want?

hd1
  • 33,938
  • 5
  • 80
  • 91
0

Not sure if I understand but git reflog shows an history of the local changes which changed the tip of a branch.

It might be what you're looking for. However the history has a limited lifetime and git gc wipes older entries.

lbonn
  • 2,499
  • 22
  • 32
0

I believe it's possible to achieve this with rebase. You want a special_master that tracks master but rebases instead of merging on pull. The only commits it will have in it are the ones that you have explicitly pulled at some point.

djechlin
  • 59,258
  • 35
  • 162
  • 290
0

This looks like meta information about what you were looking at in git. This is outside of the scope of git. You could wrap the git command (much like git achievements does) and have a secondary repository version the HEAD file and the ref file that HEAD indicates of the first repo)

Reflog stores info for only 90 days by default. This can be changed. However, if you reclone, you lose this information.

Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141