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 problems

Head: 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 branch
  • l 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 commit messages and descriptions below that too. (max char limit for message)
  • c e merges committed content with new changes into a new commit
  • if you use c with 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.
  • 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 p is what we usually do, but it will fail
    • P -f p will "force with lease" (and highlight when the argument is active)
  • stash changes with z z

    • the second z says 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 a applies 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

-F opens up the pull panel:

  • in that you use P p to push changes to origin, we can do F p to 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 e with "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 r key and then r again to continue.
  • we can unstage the changes from a hunk of from a whole file with k
  • pressing i key brings up .gitignore panel

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 i is not actually strictly an editor. there are shortcut keys that change 'pick' to 'reword', etc.
  • C-c C-c will apply the rebase, whilst C-c C-k will 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-p and alt-n to 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 i as usual to start an interactive rebase on a particular commit
  • then e will make the working directory such that you can go and edit your file. stage the changes and continue the rebase r r

combining commits

  • you can either "squash" or "fixup" with s and f respectively
  • 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 d for 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.