4

After git pull I have done git reset hard to undo the merge with commit id before merge.Somehow my entire commit is gone and I cant the see the commit in history also. But I have the commit id , on git show command I can see my changes.

How can I get back my changes and how to track what mistake I have done

Sirish
  • 9,183
  • 22
  • 72
  • 107
  • @Karl Commit I made before pull – Sirish Jun 01 '11 at 16:25
  • If you want to know what mistake you actually made, you're going to have to tell us what you did besides pull. `git pull` will *never* remove a commit from your history; you did something else. Maybe a `checkout`, maybe a `reset`? – Cascabel Jun 01 '11 at 18:37
  • @Jefromi in the below Answer I have given the commands that I executed – Sirish Jun 01 '11 at 20:56

1 Answers1

5

if you have the commit hash, and you have not run garbage collection, you can always go back to that commit with git checkout <sha1>. if you want to re-apply it on top of your current head, you could do git cherry-pick <sha1>

keppla
  • 1,753
  • 2
  • 15
  • 29
  • @keppla Is there any reason why on git reset HARD to commit id before merge reset all my changes. And is there anyway I can save this dangling commit safely at some other location – Sirish Jun 01 '11 at 13:25
  • could you please post the commands you did? i have no clear image of what you did exactly, my answer was a general one (works nearly always to recover). – keppla Jun 01 '11 at 13:28
  • @siri: `git reset --hard` is defined to drop all uncommitted changes, move the current branch to specified commit and check it out. The commit previously pointed to is recorded in the reflog, so you can always pull it out from there (`HEAD@{1}` means previous value of `HEAD`, `branchname@{1}` means previous value of *branchname* (`@{2}` means the one 2 operations back and so forth; by default the history expires after some time (I am not sure whether it's 30 or 90 days by default)) – Jan Hudec Jun 01 '11 at 13:33
  • I run following commands git pull git reset --hard 5a582b3bbcc2fb2d99132d329b90dd0ab9b42298 (commit id before merge) git pull I cant see my commit here – Sirish Jun 01 '11 at 13:37
  • @keppala After cherry pick I got a message warning: too many files (created: 3250 deleted: 828), skipping inexact rename detection Automatic cherry-pick failed. After resolving the conflicts, mark the corrected paths with 'git add ' or 'git rm ' and commit the result with: git commit -c 991f5528d4fbe036df26b1f686090f22c9c8fd18 . What does this mean – Sirish Jun 01 '11 at 13:38
  • @siri: a) and after `git reset --hard 5a582b`, what commit was your head? it should be 5a582b, which in turn should be the commit you wanted to restore, b) 'too many files', sorry, i dont know. it seems to me, your or your team's commits are not very small :). It seems to be a hell of a merge – keppla Jun 01 '11 at 13:56