Last Updated: May 15, 2019
·
987
· socjopata

Some cool stuff you should know about git #3

Here is some cool stuff you should know about git (also please check my other protips for more):

Cherry-picking commits.

Have you ever made a commit with changes, which you actually wanted to see on different branches as well? Here is a quickest and most pleasant way to cherry pick, in git. First, type: gitk -all
This will open a gui tool, displaying all your commits, made across different branches.

Now find a commit you're interrested in and right click on it and select: cherry-pick this commit

And... that's it!

‘Removing’ a commit that’s been pushed to remote.

You pushed some changes to remote branch, and shortly after you changed your mind. But you also know that messing with a git history when a remote is updated, is the easiest way to get yourself killed at work (when some of your mates goes postal, after making a pull with your 'changes'). So knowing that, what is the fastest way to drop last commit and make things straightforward for anyone else making a pull from that branch?

git revert HEAD

The aforementioned git command will create a new commit that reverses everything introduced by the accidental commit. After that you can make a push to remote and get away with what you have done. Well, sort of, since you shouldn't have pushed your crap to remote, in the first place ;)