Magit
It feels a little weird presenting my notes to the world.
Alas, emacs has begun to consume me.
C-x g is magit-status
sections
Repository Status
top of window:
Head: main enh: week49, day1 tutorial, 5 problems
Merge: origin/main enh: week49, day1 tutorial, 5 problemsHead: current local branch Merge / Rebase: depends what has been done thus far.
also gives info on tags and the number of commits between that and HEAD
something about $ for more info.
Untracked Files
this is a section!
Untracked files (2)
content/projects/ccs/dsa/leetcode/#tutorial.org#
content/projects/ccs/dsa/leetcode/some-lisp
helps us understand which files should be added to the .gitignore.
note that if you modify the .gitignore file, use g on the magit buffer to refresh.
Unstaged Changes
tracked by git, but changes have occurred within these files.
hitting TAB gives a diff
modified content/projects/_index.org
@@ -62,7 +62,7 @@ You may view the entire =tag= taxonomy [[/tags][here]], and the =author= taxonom
- @@html:<input type="checkbox" checked class="done"/>@@ [[/projects/ccs/linux/gdb][GDB]] Page not found.
- @@html:<input type="checkbox" checked class="done"/>@@ [[/projects/ccs/linux/emacs][Emacs]] Page not found.
- @@html:<input type="checkbox" class="nothing"/>@@ [[/projects/ccs/linux/regex][RegEx]] Page not found.
-- @@html:<input type="checkbox" class="nothing"/>@@ [[/projects/ccs/vc][Version Control]] Page not found.
+- @@html:<input type="checkbox" checked class="done"/>@@ [[/projects/ccs/vc][Version Control]] Page not found.
*** [[/projects/ccs/dsa][Data Structures & Algorithms]]
:PROPERTIES:
@@ -94,11 +94,11 @@ You may view the entire =tag= taxonomy [[/tags][here]], and the =author= taxonom
:PROPERTIES:
:CUSTOM_ID: languages
:END:
-- @@html:<input type="checkbox" class="done"/>@@ [[/projects/ccs/programming/languages/python][Python]] Page not found.
+- @@html:<input type="checkbox" checked class="done"/>@@ [[/projects/ccs/programming/languages/python][Python]] Page not found.
- @@html:<input type="checkbox" class="edit"/>@@ [[/projects/ccs/programming/languages/java][Java]] Page not found.
- @@html:<input type="checkbox" class="nothing"/>@@ [[/projects/ccs/programming/languages/lua][Lua]] Page not found.
- @@html:<input type="checkbox" class="edit"/>@@ [[https://github.com/abaj8494/100-days-go][Go]] Page not found.
-- @@html:<input type="checkbox" class="done"/>@@ [[/projects/ccs/programming/languages/c][C]] Page not found.
+- @@html:<input type="checkbox" checked class="done"/>@@ [[/projects/ccs/programming/languages/c][C]] Page not found.
- @@html:<input type="checkbox" class="refactor"/>@@ [[https://github.com/abaj8494/100-days-js][Javascript]] Page not found.
- @@html:<input type="checkbox" class="edit"/>@@ [[/projects/ccs/programming/languages/elisp][Elisp]] Page not found.
these are the "hunks": @@ -94,11 +94,11 @@. you can hit tab on them too, to collapse / expand.
Staged Changes
you can press s on unstaged
Stashes
no diff to be seen like with commits above, but still shows the files affected which is nice.
Unpushed Changes
commits done locally, but not pushed to the remote
Unmerged Changes
when you've done a fetch, but not merged the new code in
Unpulled Changes
indicates there can be new commits that can be pulled cleanly into the local branch without merging.
Other Sections
this depends on packages. forge, magit todos.
navigation
n, p. move forward, backwards by visible section
C-n, C-p. forward, backward by line
M-n, M-p. forward, backward by sibling
^. parent
arguments
when you press c and more options appear for what kind of commit action, you can toggle arguments and they will light up!
second video:
l l: log view current branchl o: log view other branch- tab on any commit gives diff
- you can stage hunks with
s. you can also select lines! select those lines and stage - you can write
git commitmessages and descriptions below that too. (max char limit for message) c emerges committed content with new changes into a new commit- if you use
cwith extend, amend or reword you may have to do a force-push (if that commit is already in the remote) - extend doesn't pop up with what the new commit message should be, amend does.
- reword only rewords the commit message
- you can also rebase very conveniently with
c F. it applies the unstaged changes to a commit of your choosing -
naturally, we often have changes in one branch that really should have been made on another branch.
- use spinoff:
b s, then give it the name of the branch - note: this only works if the starting branch has been pushed to the remote. slightly weird.
- use spinoff:
-
recall that any time you modify a commit that has been pushed to the remote, pushing a modified version will need to be force pushed:
P pis what we usually do, but it will failP -f pwill "force with lease" (and highlight when the argument is active)
-
stash changes with
z z- the second
zsays both for "stashing staged and unstaged changes" - you even get the option to specify a "stash message"
- you can actually see the diff in the menu (thought you couldn't).
z aapplies the changes (recall that this still keeps the stash around)-
as such use
z p"pop" instead- if you have cursor on a particular stash in the menu pane, it will pop that one, else it asks
- the second
-F opens up the pull panel:
- in that you use
P pto push changes to origin, we can doF pto pull changes from origin - usually your upstream is the branch that you are on, but we can set this to be origin with
F u(which adjusts the upstream) - you can also use
F ewith "elsewhere" which allows us to pull changes from any branch (i don't understand why you would do this)
-f is the "fetch" panel
-F with r configures rebasing.
- to continue with a rebase, press the
rkey and thenragain to continue.
- we can unstage the changes from a hunk of from a whole file with
k -
pressing
ikey brings up.gitignorepanel
third video; rebasing
- if you have changes to tracked files in your repo you will need to stash them before rebasing
- backup your branch because we might lose access to commits on the current branch! in magit you can do it with
b n
rewording commits
- the view that comes up with
r iis not actually strictly an editor. there are shortcut keys that change 'pick' to 'reword', etc. C-c C-cwill apply the rebase, whilstC-c C-kwill cancel it- after doing any rebase changes the commit history has officially changed and we would have to do a force push
reordering commits
- might be useful to adjust the narrative of the history
- can be done by using
alt-pandalt-nto move the commits around in the rebasing panel
conflicts
- once you fix the conflicts, do not press commit, instead just continue the rebase.
editing a commit
r ias usual to start an interactive rebase on a particular commit- then
ewill make the working directory such that you can go and edit your file. stage the changes and continue the rebaser r
combining commits
- you can either "squash" or "fixup" with
sandfrespectively - squashing creates a new message, whilst fixup does not.
- place the fixup below the commit you want to combine the commit into.
deleting a commit
- quite simple, just hit
dfor drop in the interactive rebase panel.
doing it all at once
note that all the above can be done all at once in one fell sweep! X is for reset and we can reset to the backup branch to try apply all rebases in one go.
Backlinks
1. Version Control /wiki/ccs/vc/
notes
it is good to keep notes about version controlling things.
I mostly use git.
git
| prefix | use-case |
|---|---|
| BUG | bug fix |
| DEV | development tool or utility |
| DOC | documentation |
| ENH | enhancement, a new feature |
| MAINT | maintainence task |
| REL | release |
| STY | stylistic change |
| TST | addition or modification of tests |