Forgit me nots

August 11, 2019 • 1 min read

Squashing commits on Windows

I know there’s a better way to do this (using rebase) but I like this way since it gives me more control.

git merge-base master yourBranch

# note commit hash

git reset --soft # enter commit hash

# all changes can now be committed again

It’s easier on *nix using the following oneliner:

git reset $(git merge-base master $(git rev-parse --abbrev-ref HEAD))

Rebasing without pulling master

Rebase using the remote master to make sure you’re really up to date. Useful when updating merge requests (on GitLab).

git pull --rebase origin master

Copy file from master to current branch

git checkout master -- yarn.lock

Useful aliases

Add all and commit

ac=!git add . && git commit

Pretty log

ls=log --pretty=format:%C(green)%h\ %C(yellow)[%ad]%Cred%d\ %Creset%s%Cblue\ [%cn] --decorate --date=relative

Update last commit with current changes

amen = !git add --all && git commit --amend

Oh no, I deleted all my work!?

Use the following command:

git reflog

and cherry-pick any commits you think could still have all your work.

Got any questions, found a mistake? You can find me on Twitter as @vnglst. You can also discuss the article on TwitterSuggest changes on Gitlab


Koen van Gilst

Koen van Gilst

Personal blog by Koen van Gilst. JavaScript developer, M.A. in Philosophy, former translator.