My git notes

rollback

git revert HEAD~1..HEAD # Roll back the last commit.

combining multiple commits into one with git rebase

Say you want to do make one commit out of the last two commits: git rebase –interactive HEAD~2 You can then press "s" on the last commit to "squash" it into the previous commit.

I made a mistake when rebasing. What do I do?

See here: http://stackoverflow.com/questions/134882/undoing-a-git-rebase You can reset the state of the working repository by using: git reflog find the place you want to go back to and, git reset --hard [email protected]{5} (replace the "5") or simply: git reset --hard ORIG_HEAD (because rebase saves the point before rebase to ORIGHEAD) You may also want to do a: git rebase -i --abort

But what if both commits were pushed

It is best to try and avoid this and only squash commits that have not themselves been published. But: You will get an error message like " error: failed to push some refs […]" "[…] hint: Updates were rejected because the tip of your current branch is behind […]"

So what do you do? Read this: http://stackoverflow.com/a/559971 If no one else has interacted with the repository, you might use git push –force, but be careful. See also git push –mirror. Also note: Be careful not to rebase branches unless they are themselves rebased on the current origin/master.

Author: jmn

Created: 2016-12-07 Wed 04:50

Validate