hylander0
hylander0

Reputation: 1100

Git Move older commit(s) to new branch so I can merge them back later

Yet Another Git Move Commit Question.

I have a master branch that all work is being committed to. A client decided feature 123 is no longer wanted in a release (to be released later). I need to pull out commit B (for a lack of my complete understanding of Git workflow, hence this question) in to another batch so I may merge it later.

Much like if I could go back in time know that those commits need to be on their own branch and do it then so I can easily do a merge when that feature is wanted.

A --> B --> C --> D (master)

Would like to do:

A --> __ --> C --> D (master)
       \
        B (Feature 123)    

So I can do this later:

A --> __ --> C --> D --> FUTURE COMMITS --> Z  (master)
       \                                /
        B -----------------------[Merge] (Feature 123)

I would like to take Commit B and Move it so Master so I can merge it into master at a later time.

I know I need to branch at that commit but I does me no good if the master still is aware of those changes. I know am thinking about this wrong so any incite is appreciated.

Also, these commits have been push to origin and have been pull down by other devs.

Upvotes: 0

Views: 94

Answers (1)

Sven Marnach
Sven Marnach

Reputation: 601361

You can create a new feature branch at B, and then rebase the master branch on top of A:

git branch feature123 B
git rebase --onto feature123^ feature123 master

This will rewrite the history of the master branch. It will replay C and D on top of A, which is likely to cause confusion with the people who already pulled these commits.

An alternative that does not match exactly what you illustrated in your diagrams but avoids reqriting the history of your master branch is to revert commit B:

git revert B

This will record a new commit on the master branch reverting the changes intorduced in B. You can later re-apply that commit by using git cherry-pick B.

Upvotes: 2

Related Questions