git使用小记---比较

变化比较

  • git diff
    比较当前未add文件与上一次add文件的区别(workingtree与index)
git diff [--options] [--] […​]  //eg.  git diff master -- Folder/  develop -- Folder/
git diff [filename]                  //eg.  git diff MyFlder/

比较未commit文件的与上次commit文件的区别(index与HEAD)

git diff --cached [filename]

比较未add文件与上次commit文件的区别(workingtree与HEAD)

git diff HEAD [filename]
git使用小记---比较_第1张图片
workingtree->index->HEAD
  • git add -p
    会显示当前未add文件与working tree文件的区别,并可选择add的方式
Stage this hunk [y,n,q,a,d,/,s,e,?]? n
y - stage this hunk
n - do not stage this hunk
q - quit; do not stage this hunk or any of the remaining ones
a - stage this hunk and all later hunks in the file
d - do not stage this hunk or any of the later hunks in the file
g - select a hunk to go to
/ - search for a hunk matching the given regex
j - leave this hunk undecided, see next undecided hunk
J - leave this hunk undecided, see next hunk
k - leave this hunk undecided, see previous undecided hunk
K - leave this hunk undecided, see previous hunk
s - split the current hunk into smaller hunks
e - manually edit the current hunk
? - print help

另附一个将不同命令执行后workingtree, index 和 HEAD之间变化的关系图。workflow

git使用小记---比较_第2张图片

你可能感兴趣的:(git使用小记---比较)