I know they exist in git reflog
, but if I push a commit to a remote repository, amend, then git push --force
(warning: pushing --force
to remote repositories should usually be avoided), will the commit that I overwrote exist somewhere?

- 1,476
- 2
- 17
- 30
2 Answers
will the commit that I overwrote exist somewhere?
Only in:
- the reflog of your local repo
- the reflog of your remote upstream repo (where that commit were previously published).
That upstream repo is usually a bare one, as kostix comments, socore.logAllRefUpdates
needs to be true, if you want to see the reflog in said bare upstream repo. - any other other local clone of your remote repo, done before your second git push (
--force
) by other people.
Note that ORIG_HEAD
(a memento from a time where reflog didn't existed yet) is not created/updated by a git commit
(like a git commit --amend
or a git commit --amend -m "new comment"
).
So if the reflog
isn't activated on a repo, ORIG_HEAD cannot be used to reference the amended commit.
-
I should be noted that usually pushes go to bare repositories, and bare repositories have the reflog disabled by default. So the second point should have a big "if" attached to it. – kostix Jun 21 '13 at 15:08
-
@kostix good point, I have included the reflog activation on bare repo in the answer. – VonC Jun 21 '13 at 15:18
-
I also beleive (though I'm lazy to check) that the `ORIG_HEAD` ref might point to the commit `HEAD` referenced just before the amendmend had been carried out. In theory, this might be able to ease saving one's neck if the reflog is for some reason disabled in a normal local repository (I mean, no `git fsck` run with manual exploration would be needed). – kostix Jun 21 '13 at 15:26
-
1@kostix Just did a `C:\Users\VonC\Prog\git\git>c:\prog\Gow\bin\grep.exe -nrHI "ORIG_HEAD" *`: the following commands do indeed an `update_ref("updating ORIG_HEAD", "ORIG_HEAD", head_commit->object.sha1`: `git merge`, `git reset`, `git resolve` (now deprecated), `git am` and `git rebase`. **Not `git commit`**. I just tested it. – VonC Jun 21 '13 at 15:58
-
Thank you. So basically it's only accessible via local and remote's reflog (which eventually gets GCed)? – mustafa.0x Jun 22 '13 at 10:47
-
@mustafa.0x yes, or it is in any other local clones done by other developers. – VonC Jun 22 '13 at 12:22
No. Your amended commit will stay in your local repo for some time, but it won't be pushed.
When pushing, Git computes the missing commits to have the remote branch at the same point as your local branch. Since your amended commit is not on the branch anymore, it won't be pushed.
An amended commit stays until a garbage collection occur. But GC check several conditions before removing a commit, so don't be afraid of losing data.

- 5,002
- 1
- 23
- 35
-
In the scenario described by OP the commit is pushed before amend. – Klas Mellbourn Jun 21 '13 at 14:40
-
Oh yes thanks, I just saw that. I must have misread the question since it wasn't edited. Very good answer from VonC BTW, I upvoted. – Guillaume Darmont Jun 21 '13 at 14:57