
If you want to see what it looks like first you can use git checkout -b newbranch the-SHA-you-pickedĪnd that’s all there is to it. Now basically just pick the SHA you want move back to and then reset back to it. This will show you something like the following: some-sha : checkout: moving from master to some-sha The first thing you want to do is to check the reflog.
#Git squash commits how to#
This post is the result of me figuring out how to undo this. Today I squashed the temporary commit into the previous commit which meant I was merging my commit with someone else’s work. Of course, you might also squash the wrong commit.

commits on the different branches updating the same line in different ways. With a merge, files are automatically merged unless there are two conflicting set of changes, i.e. Afterwards git will prompt you again to specify the commit message for the merge commits. Merging takes the commits on two different branches and combines them. If we want to merge the last commit into the temporary commit we have to do the same for the last line. Now you have to choose the commits you want, so if we want to merge the temporary commit into the second commit we have to change the pick on the third line into an s (for squash). This can help keep your repositorys history more readable and.

Git will prompt you to select the commits you want to keep, so you would see a screen that looks something like this: pick some-sha First commit message Squashing allows you to combine multiple commits in your branchs history into a single commit. To remove the temporary commit, I usually do an interactive rebase: git rebase -i HEAD~5 Once I’m ready to push all my changes I’ll remove all the temporary commits – the git term for this is squashing commits.

This can be for a number of reasons – either to just get a stopping point, or to push my changes on to a remote branch for some reason. Effectively, you are creating a new commit that replaces the old one. Changing the commit message will change the commit ID-i.e., the SHA1 checksum that names the commit. In Git, the text of the commit message is part of the commit. I tend to do temporary commits in git pretty often. You can change the most recent commit message using the git commit -amend command.
