暂存部分文件(方法一)
# git stash -p
它是一个交互式命令,我们可以一个文件一个文件的遍历,决定每个文件的操作方式:
# 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
暂存部分文件(方法二)
部分更改文件想放到暂存区,部分想保留更改,可结合 git add 和 git stash 实现:
# git add file1 file2 #保留更改文件至工作区
# git stash save -k #暂存未add的更改文件
# git reset #恢复工作区文件
恢复部分文件
# git stash list
stash@{0}
stash@{1}
stash@{2}
# git stash show -p stash@{1}
# git checkout stash@{0} -- <filename>