Last Updated: May 15, 2019
·
958
· socjopata

Some cool stuff you should know about git #1

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

Recovering deleted commits / branches

It is actually fairly hard to delete content in git. If you 'accidentally' did git reset --hard HEAD^ and threw out your last commit or deleted a branch, try to run git fsck --lost-found to see what is in 'awaiting garbage collecting' state. You will see a list of dangling commits / blobs, similar to the one below:

dangling commit 6d4372206635c5822f3900fe15d8932f1907d285
dangling blob 5789daa23ad8b866d4c1f4380c6adf153fb99e9f
dangling blob ffd820c5cca4b399718cc4e8f74e32485c16a939

If you really need some of your changes back, you can get them back by typing git merge *SHA of that branch*

Check if a branch has been merged.

Have you ever had doubts, if you actually remembered to merge some stuff from branch x to branch y? Here is a quick way to do this:

git branch --merged

The command above lists branches that had been merged to the current branch. If you want do the vice versa, there is a --no-merged command.