git revert after merge/pull

Sau khi git pull về mất một số file thì làm thế nào???

Giải pháp là dùng lệnh: git reset --hard HEAD^

HEAD refers to the current commit (generally the tip of the currently checked-out branch). You’ve already committed your merge, so HEAD is pointing to the merge commit. If you want to get back to the commit before it, use:

git reset --hard HEAD^

The ^ means “first parent of”; for a regular commit it’s the only parent, and for a merge commit it’s the commit you had checked out when you merged (i.e. the prior tip of the branch you merged into).

And of course, if you ever get really lost, just open up gitk, and either copy/paste the SHA1 of the commit you want to reset to (git reset --hard SHA1) or just right click on it and reset within gitk.

By the way, revert doesn’t mean what you think it does (it sounds like you’re using it in an svn way, maybe? but I’ve never used svn). git revert is used to create a commit which cancels out (reverts) a previous commit, by applying the reverse diff. You use it when you want to undo a single previous commit which has already been published.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s