暫存部分文件(方法一)
# git stash -p
它是一個(gè)交互式命令,我們可以一個(gè)文件一個(gè)文件的遍歷,決定每個(gè)文件的操作方式:
# git stash -p
diff --git a/cmd/scripts/cbs.sh b/cmd/scripts/cbs.sh
old mode 100644
new mode 100755
Stash mode change [y,n,q,a,d,/,?]?
[y,n,q,a,d,/,?]分別代表的含義如下:
y - stage this hunk
n - do not stage this hunk
q - quit; do not stage this hunk nor any of the remaining ones
a - stage this hunk and all later hunks in the file
d - do not stage this hunk nor 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
暫存部分文件(方法二)
部分更改文件想放到暫存區(qū),部分想保留更改,可結(jié)合 git add 和 git stash 實(shí)現(xiàn):
# git add file1 file2 #保留更改文件至工作區(qū)
# git stash save -k #暫存未add的更改文件
# git reset #恢復(fù)工作區(qū)文件
恢復(fù)部分文件
# git stash list
stash@{0}
stash@{1}
stash@{2}
# git stash show -p stash@{1}
# git checkout stash@{0} -- <filename>