views:

60

answers:

1

Often when I work on a feature branch with git, I find a bug and start fixing it right away. I don't want to switch since the new feature is often what I need to reproduce the bug. After a while I have 2-3 files that contains the bug fix plus some other non-committed files containing the new feature I'm working on.

Now I would like to merge only the bugfixed files with the master branch without merging the whole feature branch. What is the best way of doing that?

Stash saves all files, so it's not perfect. My last solution was to commit the fix, switch to master, cherry-pick, then update the Changelog and amend... It feels like I haven't found a good enough solution, so I'm asking here!

+1  A: 

You could create a new branch just for the fix:

git checkout -b fix_branch
git add -p ...
git commit -m "fix for xyz problem"
git checkout feature_branch

After that, you can decide what to do with fix_branch later, such as cherry picking it to master.

Greg Hewgill
Thanks, for smaller fixes I figured I could also checkout master, add the modified files, update the Changelog and commit.
ciscoheat