Use git cherry-pick

来源:互联网 发布:淘宝网裤子带线 编辑:程序博客网 时间:2024/04/30 01:54

If you used commit -a -m to commit other branch's changes(branch A) to the current branch(branchB) by mistake, you want to put the last commit back branch A, so use 
git cherry-pick logid
where, logid is the log id, which you can get from "git log"

The detail steps:
1. git checkout branch_B          // go to branch_B
2. git log                                   // Check the git log to get thelog id
3. git checkout branch_A       // Got the branch A
4. git cherry-pick log_id          // execute cherry-pick
5. git log                                    // Check the log and you will find it works.
6. git checkout branch_B          // go to branch_B
7. git reflog                                  // you want to reset to the position before you commit, remember the reflog_id.
8. git reset --hard reflog_id      // reset to the position before you commit

Over.