简体   繁体   中英

How do I insert a commit between two commits on a different branch?

My repository started with a single commit:

A

Then I created the branch "refactor" and added another commit:

A
 \
  B

Then I switched back to master and changed some stuff:

A--C
 \
  B

I want commit C to exist on branch "refactor" between the first and second commits, so it looks like the branch occurred after C. Something like this:

A--C
    \
     B

How do I do this?

You can rebase your refactor branch onto master.

$ git checkout refactor
$ git rebase master

but make sure refactor is a local branch, as rebase changes the commit history.

This can be done with a rebase

$ git checkout refactor
$ git rebase master

This can be done by a simple rebase:

git rebase master refactor

This will first check out refactor, then take the commits master..refactor (which should only contain B), and re-apply them on master.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM