segunda-feira, 2 de maio de 2011

Git: Recovering Lost Commits with git reflog and reset

Reviewing lost commits

The reflog command will give you a good history of what’s been happening on the head of your branches. Run it, then find the line that refers to the state that you want to get back to:

$ git reflog
... snip ...
cf42fa2... HEAD@{84}: checkout: moving to master
73b9363... HEAD@{85}: commit: Don't symlink to themes on deployment.
547cc1b... HEAD@{86}: commit: Deploy to effectif.com web server.
1dc3298... HEAD@{87}: commit: Updated the theme.
18c3f51... HEAD@{88}: commit: Verify with Google webmaster tools.
26fbb9c... HEAD@{89}: checkout: moving to effectif
The latest entries appear at the top. You can work out which branch each change was made on by looking out for lines that say “checkout: moving to …”. Commits 88 through to 85 (they’re numbered in the second column of the output) were the commits that I’d lost; all I needed to do was to get them back.

Reverting a branch to an earlier state

In short, you need to switch to the correct branch (“effectif” in my case) and then do a hard reset. The --hard options sets the HEAD of the current branch back to the commit that you specify:

$ git checkout effectif
$ git reset --hard 73b9363

Nenhum comentário:

Postar um comentário

Drunk Penguins

Drunk Penguins
Drunk Penguins