I git git. No, seriously... I've also used several git clients over my short lifetime, my current favourite is the awesome and beautiful (and beautifully cross-platform) gitkraken tig (ncurses git client) - although if I had to choose a gui git client it would definitely be gitkraken.
Info |
---|
Full disclosure: I am the AUR (Arch Linux User Repository) package maintainer for gitkraken (standalone version for air-gapped networks and labs). |
However, sometimes I need to do stuff that's just easier in git bashon the command line. Below are several of these commands that I always seem to forget (dang you nice git client - making me forget my terminal roots...).
Table of Contents | ||||
---|---|---|---|---|
|
git reset back to a previous commit
Sometimes you might want to take a local branch back to a previous commit (or state... like in between several amend commits) without actually reverting commits.
...
Code Block | ||
---|---|---|
| ||
git reset --hard HEAD |
Reset specific file to previous commit version
From time to time you may need/want to reset a specific file to a version in a previous commit. What you essentially want to do is "checkout" the file from said commit:
Code Block | ||||
---|---|---|---|---|
| ||||
git checkout <COMMIT-HASH> -- path/file |
For example, suppose I want to check reset the current file found in the path (relative to the git root foler) "i3/config
", I would do:
Code Block | ||||
---|---|---|---|---|
| ||||
git checkout 3b5e3ff7ab0c3d61984532950a1c7acfe3f9efa6 -- i3/config |
where 3b5e3ff7ab0c3d61984532950a1c7acfe3f9efa6
is the commit hash (you can also use the "short" hash 3b5e3ff
).
Create orphan branch
In some instances you might need/want to create a branch which is not based on another branch. This is known as an orphan branch. Some git front-ends provide a nice way of doing this but many (even good ones) do not. No matter, you can always create one from the command line, like so:
...