Question

I'm working on a new private (local) branch called TOPIC implementing a new feature. After working on this new feature for a while, I realized that some of the stuff that I wrote really should be in it's own branch, GIZMO. But I also have uncommitted files that should not be part of GIZMO

So lets say that I have the following files that haven't been committed:

foo/a.cpp
foo/b.cpp
foo/c.cpp
feature/magic.cpp
feature/unicorns.cpp
feature/gold.cpp

What I want to do is create a new topic branch GIZMO consisting of foo/*, so that I can commit that and merge it back to master, and then continue working on TOPIC.

This is different than other questions I have seen, because in those questions a new branch was being created from all uncommitted changes, and that's not what I want to do here. Here, I only want to make a new branch out of some of my uncommitted changes.

Is this possible?

Was it helpful?

Solution

Can you commit what you want, stash your un-commited changes. Make a new branch, pop the stash, commit the changes, switch back to whatever branch you want?

So for your example, commit your feature/* files. Stash your foo/* files. Switch to a new branch based off Master. Pop your stash, which should only be foo/* files. Commit those to your new branch, then switch back to Master.

If you don't want to commit your feature/* files first, then stash everything, commit only foo/* on the new branch. Make another new stash for feature/* files again, and re-pop that when you switch back to Master.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top