On Mar 13, 6:33 am, KaibutsuX <sean.gri...@gmail.com> wrote:
> This is all on the master branch.
> I guess what I'm looking for is a way to do a stash, but not only
> stash the file diffs, but also any commits that were made.
> If that doesn't make sense, here's a very simple example of what I
> usually do at work:
> Work on some low priority project where I fix one file, commit it with
> a message, then fix a second file and commit it with another message.
> But I'm not done with the whole project yet, just two files so I'm not
> pushing my work yet.
> But then someone gives me a high priority task, so I have to work on
> that immediately. What I usually do in this instance is just reset my
> HEAD^2 commits and then stash my changes, fix the high priority,
> commit and push it then apply my low priority stash to continue
> working on it. But now I've lost the commit history which was the 2
> commits I already made because I had to reset them in order to do the
> high pri fix.
> I wish there was a way I could stash my local commits (resetting my
> working directory) but when I reapply that stash have all the commits
> and commit messages come back with them. And I would like to be able
> to do this without making a new branch.
> Does that make sense?
I think you should take into account that Git, being a DVCS, supports
cheap local branches and make use of them.
When you get assigned a high-prio task, do this:
1) Fork a temporary branch out of the HEAD:
$ git branch temp
Now your two low-prio commits are reachable via that branch.
2) Reset master to zap low-prio commits, do your high-prio task.
3) Cherry-pick those two commits (git cherry-pick) from the temporary
branch then delete it.
Alternative (better) approach:
(steps 1-2 as above)
3) Check out the temp branch and rebase it on top of master:
$ git checkout temp
$ git rebase master
Now your temp branch has two low-prio commits applied on top of the
4) Check out the master branch back, merge your temp branch and delete
$ git checkout master
$ git merge temp
$ git branch -d temp
Since after step (3) the temp branch has the tip of the master branch
as the "merge base" between these two branches, the merge will result
You received this message because you are subscribed to the Google Groups "Git
for human beings" group.
To post to this group, send email to git-us...@googlegroups.com.
To unsubscribe from this group, send email to
For more options, visit this group at