If I only have a master
branch and I reset to a previous stage, followed by a forced update, are those commit messages lost after I run git gc
?

- 7,347
- 5
- 34
- 65
-
Possible duplicate of [How can I undo git reset --hard HEAD~1?](https://stackoverflow.com/questions/5473/how-can-i-undo-git-reset-hard-head1) – phd Jan 13 '19 at 19:40
-
https://stackoverflow.com/search?q=%5Bgit%5D+undo+reset+hard – phd Jan 13 '19 at 19:40
1 Answers
Not immediately. By default, Git keeps something called a reflog, which tracks the history of each reference (including branches) for 90 days. Until the reflog entry referencing those commits expires, Git will continue to hold the objects that they refer to, including the commit object, which contains the commit message. Only after that point will git gc
clean them up.
If you want to find former commits on your master
branch, you can run git reflog master
to find the status of that branch at each point in time. You can then find the commit hash for the commit you want, verify that it's the one you want with git show
, and if necessary, create a new branch from it with git checkout -b
.
You can also run plain git reflog
to see the HEAD
reflog, which shows you the history of what's been checked out regardless of branch.

- 64,793
- 6
- 84
- 100