• search a commit in local/remote branch
    • git branch (-r) --contains commit_hash
  • clean all
    • git clean -fd ; git reset --hard;
  • git worktree
    • git worktree add -b add-feature ../feature master
  • Discard all local changes, but save them for possible re-use later
    • git stash
  • Discarding local changes (permanently) to a file
    • git checkout -- <file>
  • Discard all local changes to all files permanently
    • git reset --hard
  • Delete untracked files and dirs
    • git clean -fd
  • Edit global config file:
    • git config --global --edit
  • Find commit/author by each line
    • git blame / tig blame
  • Back to previous commit
    • git reset e12d8ef^
  • Modify a commit message
    • git commit --amend

Tig

  • main view (tig)
    • 閱覽 commit log 的畫面
    • 可以 j/k 上下移動, enter 查看 commit 的詳細 diff 變更,然後用 q 關閉 diff 畫面
    • 對選中的 commit 按 t 可以進到 tree view
  • tree view ( 查看 commit 當時的 repo 檔案內容 )
  • status view (在其他view按大寫S)/ (tig status)
    • 用 u 來把檔案加入或移出這次的 commit
    • 對檔案按 enter 查看 diff 變更,此時可以用 @ 往下選 chunk,再按 u 來只加入選中的 chunk,或是用 j/k 上下移動,按數字 1 來只加入單行的修改,最後按 q 跳出 diff
    • 按下大寫 C 能 git commit

Leave a Reply

Close Menu