I'm on branch feature-x
doing some work, when I suddenly encounter an issue which should really be solved on another branch, hotfix
.
I want to create a commit with that change, but on the hotfix
branch.
From this question I understand that the standard procedure would be to
# On branch feature-x
git stash
git checkout hotfix
git stash pop
git add -A
git commit -m "Fixed issue #562"
That would work if I didn't have many changes on branch feature-x
already underway, which would throw a conflict with the branch hotfix
. I want to avoid having to resolve unnecessary conflicts.
To avoid that, I was thinking that I could only extract a single file from the stash, as noted on this answer. So the procedure would be:
# On branch feature-x
git stash
git checkout hotfix
git checkout stash@{0} -- <src/buggyfile.xxx>
git add -A
git commit -m "Fixed issue #562"
And then I should go back to feature-x
git checkout feature-x
git stash pop
While there's a way to bring files from another branch directly, I want to know if there's a way to send files to another branch, without all this hassle. The actual modification is only a couple characters.