示例会话:
$ cd "$(mktemp --directory)"
$ git init
Initialized empty Git repository in /tmp/tmp.7HssIqQ2qT/.git/
$ echo foo > foo
$ echo bar > bar
$ git add .
$ git commit --message="Initial commit"
[master (root-commit) c6db082] Initial commit
2 files changed, 2 insertions(+)
create mode 100644 bar
create mode 100644 foo
$ echo foo2 > foo
$ echo baz > baz
$ git add foo baz
$ echo foo3 >> foo
$ echo bar2 > bar
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: baz
modified: foo
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: bar
modified: foo
基本上,如何提交上述更改以及尚未提交的更改,注意只有“foo”的部分更改已经被暂存?迄今为止我能想到的最简单的方法是创建两个存储,并以相反的顺序弹出它们,但它并不是很有效:
$ git stash --include-untracked --keep-index
Saved working directory and index state WIP on master: 3dba6aa Initial commit
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: baz
modified: foo
$ git stash --include-untracked
$ git status
On branch master
nothing to commit, working tree clean
$ git stash pop stash@{1}
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: baz
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: bar
modified: foo
Dropped stash@{1} (6fb8f81bdb2dc9fc1f218e7c25e74ad32c01fc0e)
不知何故,baz作为最老的stash的一部分被弹出,因此状态已经混乱。
git-add
之间,baz没有发生变化,以及对工作树的后续修改。而两个未提交的foo
的副本则不相同。 - torekfoo
,而工作树包含一个两行文件,先读取foo
然后是bar
。差异 是根据这两个文件副本的请求动态计算的。 - torek