Add lazygit
This commit is contained in:
commit
a018367b49
85
programmes/lazygit.md
Normal file
85
programmes/lazygit.md
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
# `lazygit`
|
||||||
|
|
||||||
|
**Why would you care:** Lazygit really shines at rearranging commits and doing partial staging of changes. It's also just a fairly comfortable TUI for git. I don't do *everything* in Lazygit but it's nice for most operations.
|
||||||
|
|
||||||
|
Open `lazygit` in a git directory.
|
||||||
|
|
||||||
|
At any time, press `?` to get a context-sensitive list of pressable keys.
|
||||||
|
|
||||||
|
## Switch and create branches
|
||||||
|
|
||||||
|
Click or use Left/Right arrow to switch to branch pane.
|
||||||
|
|
||||||
|
Move up and down the branch list with Up/Down.
|
||||||
|
|
||||||
|
Use Space to switch to the chosen branch.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Press `n` to create a new branch from the current branch.
|
||||||
|
|
||||||
|
Use `p` to pull and `P` (shift+p) to push.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Press `c` to switch to a branch by name — you get an interactive text box with filtered list of branches. (You can alternatively use `/` to directly search like you are in less, but this seems like a faster way to get what you want.)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Press `M` on a branch to merge that branch into this one. Press `r` to rebase this branch onto that one.
|
||||||
|
|
||||||
|
## Committing
|
||||||
|
|
||||||
|
Switch to the files pane.
|
||||||
|
|
||||||
|
Use Up/Down to choose a file/directory.
|
||||||
|
|
||||||
|
Press space to stage/unstage a whole file/directory.
|
||||||
|
|
||||||
|
**Magic:** When on a file, you can see the diff on the right-hand-side. You can **click** on a line and press space to stage/unstage a single line(!!!).
|
||||||
|
|
||||||
|
Press `c` to make a commit — you get a single-line text editor. If you want to use a full editor, use `C`.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Press `A` (amend) to add your changes to the latest commit on the branch — you can also choose an older commit in the commit pane and press `A` to amend a previous commit.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
If you need to refresh the files pane, press `r`.
|
||||||
|
|
||||||
|
Press `s` to stash changes (I rarely use this, mostly just if I have changes that I need to switch onto a different branch when you can't change branch cleanly).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Rearranging commits
|
||||||
|
|
||||||
|
In the commits pane:
|
||||||
|
|
||||||
|
`c` (\~copy) to add or remove a commit to/from your 'clipboard' (you will see it highlighted). You can then switch branch or whatever and use `v`(\~paste) to copy those commits to the tip of a branch. (This is essentially just cherry-pick.)
|
||||||
|
|
||||||
|
`s` to squash a commit down.
|
||||||
|
|
||||||
|
`R` to reword a commit (in a full editor; use `r` for single-line editor).
|
||||||
|
|
||||||
|
`d` to delete a commit (removes the commit from history).
|
||||||
|
|
||||||
|
`t` to revert a commit (i.e. create a reversion commit that undoes the changes).
|
||||||
|
|
||||||
|
`ctrl+j`/`ctrl+k` to move the commit up/down in the list.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Merge conflicts
|
||||||
|
|
||||||
|
Some operations (merge, rebase, cherrypick, move commit, delete commit) will leave you with conflicts if they can't be applied cleanly.
|
||||||
|
|
||||||
|
You can fix them up (I often use PyCharm → Ctrl+A → Resolve conflicts, it has a magic wand feature which does most things) and then press `m` then choose `continue`.
|
||||||
|
|
||||||
|
If you can't resolve, you can always press `m` then choose `abort` to stop whatever is going on — this is a very handy escape hatch.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Other tips
|
||||||
|
|
||||||
|
On a branch or commit: `g` brings up the 'reset' menu. I often use `g` → `soft` on a commit to un-commit things (this rolls back the branch to a previous point but keeps the changes as staged changes) so that I can tweak them however I like. When doing dirty work I will often make commits with rubbish names like 'STASH' and then later un-commit them and commit them thoughtfully.
|
Loading…
Reference in New Issue
Block a user