Reputation: 33986
I have some incorrect commit/push
on my branch, then I want to revert to an old correct commit and push it on the current branch.
I have a problem with:
git log
new: xxxxxxx
...
old: ac758a3
git checkout ac758a3
git commit -m 'revert to old branch (ac758a3) to push it on current branch'
Out:
HEAD detached at ac758a3
nothing to commit, working directory clean
[EDIT]
I want revert to A(old commit) and push it on current branch (the same branch).
What is the fast solution?
Thanks in advance.
Upvotes: 9
Views: 14154
Reputation: 14042
These steps seems better to me, going back to a previous commit as a new commit:
First choose the commit-id you want to return to (using $ git log
for example).
Then:
$ git checkout <commit-id> .
$ git commit -m "Reverting to <commit-id>"
$ git push
Re-posting from (thanks, Tolani):
https://medium.com/swlh/using-git-how-to-go-back-to-a-previous-commit-8579ccc8180f
Upvotes: 1
Reputation: 1701
if you have already pushed commits and people have pulled it already, best solution is to add a new commit which effectively undo previous commits. Then things are normal.
you can undo series of commits using git revert
%git revert --no-edit SHA1..SHA2
This will apply patches in reverse sequence and undoing changes. Please see git revert documentation for more information.
Upvotes: 0
Reputation: 1110
git reset --hard <commit-id>
is your friend dear.
Follow below steps:
git log
git reset --hard <commit-id-copied-in-step-2 above>
git push origin <my-feature-branch> -f
.Note: You will not be able to push it normally, you have to push it forcefully since we have changed the history of that branch and is not in sync with remote.
Upvotes: 13