Reputation: 1293
I have been using git commands for my project.
If I made one wrong commit and pushed into my branch. On that time, how can I update it back ?
If I need to copy last three commits to new branch, how can I do?
Need programmers help soon... Thanks in advance.
Upvotes: 2
Views: 3749
Reputation: 42094
To revert your faulty commit, simply use git revert
and push that.
It's not going to remove it from the project history, though. For that you'd need to locally rewrite said history, and push that; but many upstream repositories prevent that since it messes up everyone else-s workflow.
To copy the three last commits from a branch feature
to your current branch, use the following:
git cherry-pick feature~3..feature
Upvotes: 2
Reputation: 1624
reset
and push -f
.Now situation.
A - B - C - D ← HEAD and wrong commit
You should rollback HEAD.
git reset --hard HEAD~1
now
A - B - C ← HEAD
finally, you should force push to your remote repository.
git push origin your_branch -f
cherry-pick
Now situation.
need to copy
|---------|
A - B - C - D - E← old branch
\
F - G - H ← new branch
use cherry-pick
on your new branch
git cherry-pick <C commit hash>
git cherry-pick <D commit hash>
git cherry-pick <E commit hash>
now
A - B - C - D - E← old branch
\
F - G - H - C' - D' - E'← new branch
Upvotes: 2