Git Revision Control

先說結論:git is a powerful revision control, but too complicated and difficult to use.

不過基本上也沒有更好的選擇,如下圖。我用過 CVS and Subversion, 也不怎麽直覺。

仍然好的 revision control 習慣可以避免你下地獄。因此還是要記錄一下。

image-20221119170505731

最常用的 git command

  • git config
  • git status
  • git log
  • git diff or git difftool

Git Config 顯示和設定

1
$ git config --list   # 顯示所有 configuration

Git diff or git difftool

簡單的修改用 git diff 檢查就好。

Powershell 的 git diff 非常好,包含不變的上下三行 codes, 改變的地方用顔色區別,非常清楚。

image-20221119171209544

Difftool: PC 使用 Beyond Compare

1
2
3
4
5
git config --global diff.tool bc
git config --global difftool.bc.path "D:\Program Files\Beyond Compare 4\BComp.exe"
git config --global merge.tool bc
git config --global mergetool.bc.path "D:\Program Files\Beyond Compare 4\BComp.exe"
git config --global alias.mydiff "difftool --dir-diff --tool=bc --no-prompt"

如何 git diff rename file?

rename file 的問題是原始 file status -> delete.

新的 file 可能尚未 stage. use git add . 會自動改成 rename, 最好用 git rename!!

Git diff an uncommitted file

git diff path/to/file

Git diff a committed file

git diff HEAD^ HEAD – path/to/file

Unstage a file?

git reset HEAD – path/to/file