1

After a filter-branch on master (to add sign-off), I have this :

A-B-C-D-E-F (master)

A'-X-Y-Z (branch xxx)

where A' is the old initial commit. I want to "reconnect" my branch "xxx" to master, to initial commit A to have something like this :

A-B-C-D-E-F (master)
 \
  X-Y-Z (branch xxx)

How to do that ? Thanks

xnopre
  • 583
  • 1
  • 4
  • 10

2 Answers2

1

3-steps solution with backup option included :

# create a backup for the branch
git checkout -b backup-xxx xxx

# force position of branch xxx at A
git branch -f xxx A

# get the commits you wanted from the backup branch
git checkout xxx
git cherry-pick X Y Z

You'll have backup-xxx in the state xxx was before the operations, just in case you regret your move later.

Backup plan :

# to restore branch xxx in its previous state
git branch -f xxx backup-xxx
Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
1

You can follow the steps.

git checkout master
git checkout <SHA-HASH-OF-A-AFTER-FILTER-BRANCH> #Now your head should be in detached state at commit-hash of A
git checkout -b <NewConnectedBranch> #B is created from A commit
git cherry-pick X..Z #Applying changes from the disconnected branch
Mohamed Anees A
  • 4,119
  • 1
  • 22
  • 35