我不明白git stash push
与其pathspec
参数一起使用时的行为。
根据文档:
当将路径规范提供给 git stash push 时,新的存储条目仅记录与路径规范匹配的文件的修改状态。
在处理暂存区域中的更改时,使用后暂存区域git stash push -- folder
中的所有内容folder
都会按预期消失。但隐藏的更改不仅包括暂存区域中的内容folder
,还包括暂存区域中的所有其他更改。
root@96b24c3e98b4:/# git version
git version 2.27.0
root@96b24c3e98b4:/# git init tmp
Initialized empty Git repository in /tmp/.git/
root@96b24c3e98b4:/# cd tmp
root@96b24c3e98b4:/tmp# mkdir folder
root@96b24c3e98b4:/tmp# echo ok1 >folder/first.txt
root@96b24c3e98b4:/tmp# echo ok1 >second.txt
root@96b24c3e98b4:/tmp# git add .
root@96b24c3e98b4:/tmp# git commit -m tmp
[master (root-commit) a3163c3] tmp
2 files changed, 2 insertions(+)
create mode 100644 folder/first.txt
create mode 100644 second.txt
root@96b24c3e98b4:/tmp# git status
On branch master
nothing to commit, working tree clean
root@96b24c3e98b4:/tmp# echo ok2 >folder/first.txt
root@96b24c3e98b4:/tmp# echo ok2 >second.txt
root@96b24c3e98b4:/tmp# git add .
root@96b24c3e98b4:/tmp# git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: folder/first.txt
modified: second.txt
root@96b24c3e98b4:/tmp# git stash push -- folder
Saved working directory and index state WIP on master: a3163c3 tmp
root@96b24c3e98b4:/tmp# git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: second.txt
root@96b24c3e98b4:/tmp# git stash show -p
diff --git a/folder/first.txt b/folder/first.txt
index 28864ea..523b808 100644
--- a/folder/first.txt
+++ b/folder/first.txt
@@ -1 +1 @@
-ok1
+ok2
diff --git a/second.txt b/second.txt
index 28864ea..523b808 100644
--- a/second.txt
+++ b/second.txt
@@ -1 +1 @@
-ok1
+ok2
在这个例子中,为什么second.txt
最终会出现在存储条目中?