for example: I want to recover to the last 3 commit in remote?
Asked
Active
Viewed 42 times
-1
-
1What do you mean by 'recover'? Do you mean view the code at that particular snapshot, for a past commit? – Leigh May 19 '14 at 03:51
-
I suggest you reading http://stackoverflow.com/help/how-to-ask and edit this question to fulfill the standards of this page. – Florian Neumann May 19 '14 at 06:53
1 Answers
0
What you fetch from a remote is the full history of a repo and its branches.
But once fetched, nothing prevents you to reset your branch to 3 commits back:
git checkout yourBranch
git reset --hard HEAD~3
Make sure you don't have any work in progress (they would be erase), and you would have to force your push to the upstream branch:
git push -f origin yourBranch
This isn't considered a good practice if you have others fetching that same branch from the same remote repo.
The other technique (which doesn't involve rewriting the history) is to revert: see for instance "Reverting a series of pushed merges and commits in Git (without rewriting history)"
git revert HEAD~3..HEAD
That will create a new commit which will cancel the last 3. You can push it as usual.