Ravi S. Rāmphal

svādhyāya // contributing to the understanding of myself

Some Git Tricks

Here are a couple of git commands I have mastered on the job since starting:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
  git add -p                         # stage partially (in patches)
  git add -p <filename>              # stage partially (in patches) for a given file
  git reset -p                       # unstage partially (in patches)
  git reset -p <filename>            # unstage partially (in patches) for a given file
  git checkout -p                    # undo partially (in patches)
  git checkout -p <filename>         # undo partially (in patches) for a given file

  git commit --amend                 # add changes to previous (*unpushed*) commit and update commit message

  git diff                           # see changes so far
  git diff --staged                  # see staged changes

  git show <commit>                  # show the changes for a given commit

  git revert <commit>                # revert a given commit

  git stash                          # stash current changes
  git stash list                     # show list of stashed changes
  git stash show -p stash@{<number>} # show specific changes for a given stash
  git apply                          # apply the most recent stash
  git apply stash@{<number>}         # apply a given stash
  git stash clear                    # clear all stashed changes

  git reset --soft HEAD~1            # undo the last commit, but still keep the changes
  git reset --soft <commit>          # undo a given commit, but still keep the changes
  git reset --hard <commit>          # reset the state of all files to that of a given commit (discarding changes)

  git bisect
  git bisect start
  git bisect bad
  git bisect good
  git bisect reset

Comments