I was woking on a feature and it was getting late. I wanted to save my work to VCS. I should've used stash but I forgot about it. I didn't want to commit half-done feature, so I decided to create new local branch and save my work there. So I did git branch newlocalbranch
and git commit -m 'in the middle of task'
; But then I realized, that when I will merge this local-branch into my official feature-dedicated branch (with task id) that invalid commit would still appear in my feature branch. What I want now, is to go back in time to the point where I am in my feature branch with all these changes that I've made. I would then stash them and go home.

- 2,658
- 5
- 20
- 35
-
Your question is not clear. But git fast forward merge might help you . http://stackoverflow.com/questions/2850369/why-does-git-fast-forward-merges-by-default – Vishal Rajole Dec 25 '15 at 16:13
2 Answers
You can just do a soft-reset to the branch you branched off from. That way, you will reset the branch pointer to that branch, but keep all made changes. So afterwards, you can continue working on it and then create a proper commit.
So if you came from master
before, this would be the command:
git reset --soft master
That would be for a situation like this:
master
↓
* --- * --- *
\
\
* [in the middle of task]
↑
newlocalbranch
The alternative to that would be to continue working on the branch until you complete the work, and then amending that “in the middle of task” commit so it contains the full change and has a proper name. For that you would do git commit --amend --edit
. This will basically replace that “in the middle of task” commit with a new one containing all changes from the original commit and whatever you added to the index (Usually, the command is used to fix the last commit when you forgot something). Afterwards, you could do a normal fast-forward merge back onto master and that new refined commit would be the one that appeared in the history.

- 369,085
- 72
- 557
- 602
-
-
1thanks. `git reset --soft` worked. Though I had to checkout `master` branc h after that. I kinda expected that `git reset --soft` would do that for me. – dKab Dec 28 '15 at 07:30
-
1Reset will always act on the current branch, moving its branch pointer to the commit you specify. Instead of master you also could have specified some commit you want to move your branch too. That's why the command does not change the checked out branch your on. – poke Dec 28 '15 at 08:18
After merging your newlocalbranch
into feature branch and commiting finished work, but before pushing you can squash
/fixup
commits into one. See git guide on this

- 18,013
- 10
- 47
- 53