0

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?

Community
  • 1
  • 1
John Dibling
  • 99,718
  • 31
  • 186
  • 324

1 Answers1

2

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.

John Dibling
  • 99,718
  • 31
  • 186
  • 324
dckuehn
  • 2,427
  • 3
  • 27
  • 37
  • I *could*, but I'm using a branch naming scheme in such a way that the `GIZMO` stuff doesn't match the (real) name I have for `TOPIC`. I'd prefer to create a whole new branch out of just some of the uncommitted stuff. – John Dibling May 08 '14 at 16:06
  • I don't see how a branch naming scheme will prevent you from stashing/switching/popping. Are the file names themselves different? – dckuehn May 08 '14 at 16:07
  • Oh, and also, the `feature/*` files aren't really in a state where I'd want to commit them now. Sometimes I might be able to `--amend` the commit later, but I was hoping for a more direct solution. – John Dibling May 08 '14 at 16:08
  • 1
    Your edit clarified some misunderstandings I had about what you were suggesting. This may actually work better than I initially thought. – John Dibling May 08 '14 at 16:09
  • Then stash everything and only commit the `foo/*` files. Re-stash the `feature/*` files and pop back on Master. – dckuehn May 08 '14 at 16:09
  • If my answer helped you solve your problem, would you mind accepting it? If not, not a big deal. – dckuehn May 08 '14 at 19:54
  • 1
    No of course u would not mind at all, and I will. I just wanted to see if I could solicit some other answers first. Thanks for your answer. – John Dibling May 09 '14 at 00:36