git在修改上次提交时隐藏(在gui中)-pop不会弹出任何内容

git在修改上次提交时隐藏(在gui中)-pop不会弹出任何内容,git,git-stash,Git,Git Stash,因此,我有一些未分期的更改和一些分期的更改。我发布 Welcome to Git (version 1.8.3-preview20130601) $ git stash save --keep-index Saved working directory and index state WIP on master: ab0d18d Setup of alarms f or network service + Logging exceptions + long arithmetic HEAD is

因此,我有一些未分期的更改和一些分期的更改。我发布

Welcome to Git (version 1.8.3-preview20130601)
$ git stash save --keep-index
Saved working directory and index state WIP on master: ab0d18d Setup of alarms f
or network service + Logging exceptions + long arithmetic
HEAD is now at ab0d18d Setup of alarms for network service + Logging exceptions
+ long arithmetic
$ git stash
Saved working directory and index state WIP on master: ab0d18d Setup of alarms f
or network service + Logging exceptions + long arithmetic
HEAD is now at ab0d18d Setup of alarms for network service + Logging exceptions
+ long arithmetic
然后在gui中点击amend last commit,将ab0d18d提交拆分为更小的提交。我打开了一些文件,然后点击

$ git stash save --keep-index
Saved working directory and index state WIP on master: ab0d18d Setup of alarms f
or network service + Logging exceptions + long arithmetic
HEAD is now at ab0d18d Setup of alarms for network service + Logging exceptions
+ long arithmetic
重复上述程序:

$ git stash save --keep-index
Saved working directory and index state WIP on master: ab0d18d Setup of alarms f
or network service + Logging exceptions + long arithmetic
HEAD is now at ab0d18d Setup of alarms for network service + Logging exceptions
+ long arithmetic
然后我编辑了提交消息并提交了。然后我发布了
git stash pop
,开始取回我的存储并一个接一个地提交它们

$ git stash pop
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       TODO.txt
nothing added to commit but untracked files present (use "git add" to track)
Dropped refs/stash@{0} (43facd88ea3548071b196324523bd017d680d6dd)
现在在gui中点击修改提交。不确定它对应于哪个命令,但git commit--amend不起作用

当处于修改状态时,再次在gui中取消存储文件f3(单击该文件,使其在未存储区域移动-将是
git reset HEAD f3
,但这也不起作用),然后

获取:

# # On branch master
nothing to commit, working directory clean
Dropped refs/stash@{0} (898687d73b65ccc9e10cd826bc12fda1a4759651)

预期:f3修改将显示

/我将在下面保留第一个较长的答复(稍后可能会尝试将其移到新问题),但现在有一个“复制示例”,我将介绍它。不过,让我在这里列出一些要点

  • git stash
    始终同时隐藏索引和工作目录。有人可能会认为,
    ——keep index
    会使它隐藏得更多,或者会改变
    pop
    上处理隐藏值的方式。没有!默认情况下,
    git stash apply
    git stash pop
    都会将分离的索引更改混合在一起。添加
    --保留索引
    不会改变这一点。只有
    --index
    参数用于
    应用
    弹出
    尝试避免两者混合

  • git stash
    保存的“工作目录”实际上将金额保存为当前
    头的更改。这意味着,如果索引从
    头更改为
    ,但当前工作目录没有更改,则“分支上的WIP…”提交中实际上没有保存任何更改。(我认为,这是git stash中的一个bug。我已经向git邮件列表发送了一个测试用例和可能的修复程序。对于“正常”的情况,这是可以的,但是如果您拆分了一些部分,然后想稍后使用
    git stash branch
    恢复您的确切状态,它会删除工作目录状态。这就是造成您的问题的原因。)

  • 应用隐藏尝试对当前状态进行更改,以反映隐藏状态中的更改。这可能很复杂,因为当前状态不一定与保存存储时的状态相同

  • 下面是
    gitgui
    正在做的事情。当您启动它时,您就有了这个(实际提交数量当然会有所不同)。未标记的“主设备上的在制品”是“第一个”存储,现在
    stash@{1}

    $ git stash list
    stash@{0}: WIP on master: c93c8fe tobeamended123
    stash@{1}: WIP on master: c93c8fe tobeamended123
    $ git log --decorate --oneline --graph --all 'stash@{1}'
    *   3d01942 (refs/stash) WIP on master: c93c8fe tobeamended123
    |\  
    | * 6be9135 index on master: c93c8fe tobeamended123
    |/  
    | *   de8038c WIP on master: c93c8fe tobeamended123
    | |\  
    |/ /  
    | * 3db6cfc index on master: c93c8fe tobeamended123
    |/  
    * c93c8fe (HEAD, master) tobeamended123
    * 828d5cf base123
    
    现在在
    git-gui
    中,当您选择“修改最后一次提交”时,它会找到头部提交的引用(
    c93c8fe
    ,在我的例子中)。它实际上(还)没有对它做任何事情。但是,只要你点击
    f3
    将其解压,它就会做一些事情:它抓取以前版本的
    f3
    (我不确定gui下面使用的是什么,我猜应该是
    HEAD^
    的副本)并将其填充到索引中。如果您检查
    f3
    它仍然有多余的一行,但是如果您
    git show:0:f3
    查看索引中的版本,它就不再有那一行了

    请注意,没有任何引用因gui鼠标单击而更改,也没有新的提交。所有操作都发生在索引内部

    接下来,返回命令行并运行:

    $ git stash save --keep-index
    
    这产生了第三对提交,一对提交索引,一对提交当前目录。索引版本在
    f1
    f2
    中有多余的一行,而在
    f3
    中没有多余的一行。当前目录版本应该(人们会认为)在所有三个文件中都有额外的一行,但是,唉,它没有,因为
    git stash save
    比较当前目录和
    HEAD
    commit,而额外的一行在
    HEAD
    commit中,所以它不在隐藏版本中

    不幸的是,您使用了
    --keep index
    参数,因此现在工作目录版本与隐藏的索引版本相同。文件
    f3
    不再有多余的行

    从现在起,问题依然存在(更改已经消失,
    ——keep index
    抛出了它)。当然,您可以从原始提交(“tobeamend123”)中恢复它。但这就是本例中出现问题的地方:命令行
    保存了索引,然后将工作目录与
    头进行比较,头没有更改,因此没有将(未更改)保存到
    f3


    我没有看到灾难,但我看到了一些令人困惑的事情,我敢打赌这让你困惑。我不知道你为什么使用上面的
    ——保持索引。(事实上,我不确定什么用例
    --keep index
    可能用于1,在我看来
    apply
    pop
    可能默认为
    --index
    ,但这完全是另一回事……)而且,您总共进行了四次“推送”,只“推送”了一次,剩下三次

    [1我在文档中找到了预期的用例:用于在提交索引之前测试索引中当前的内容。但是等等,huhwha?,
    --keep index
    确实提交了,在
    stash
    参考上。您不妨还是提交,使用
    git checkout-b test stash
    将其安全隔离,直到'我们对此很满意。如果测试失败,需要修改,则该隐藏将发生冲突。如果测试成功,则可以将有效的提交拉入/快进合并到以前的分支中。]

    “tl;dr”的简短回答 运行
    git stash list
    。您将看到以下列表:

    stash@{0}: WIP on master: ab0d18d Setup of alarms ...
    stash@{1}: WIP on master: ...
    
    项。使用
    git stash apply--index'stash@{n}
    --index
    是可选的)尝试应用每个保存的st
    $ git stash save --keep-index
    
    stash@{0}: WIP on master: ab0d18d Setup of alarms ...
    stash@{1}: WIP on master: ...
    
    * 67dec43 (HEAD, master) "amendme" commit
    * 9c37840 previous commit
    
    * 68c51f3 (HEAD, master) replacement for "amendme" commit
    * 9c37840 previous commit
    
    $ git log --graph --decorate --oneline master 67dec43
    * 68c51f3 (HEAD, master) replacement for "amendme" commit
    | * 67dec43 "amendme" commit
    |/  
    * 9c37840 previous commit
    
    $ git log --graph --decorate --oneline
    *   3c97241 (refs/stash) WIP on master: 67dec43 "amendme" commit
    |\  
    | * f3a50e9 index on master: 67dec43 "amendme" commit
    |/  
    * 67dec43 (HEAD, master) "amendme" commit
    * 9c37840 previous commit
    * 84408ef base
    $ echo 'better changes for f3' > f3
    $ git add f3
    $ git commit --amend -m 'replacement for "amendme" commit'
    $ git log --graph --decorate --oneline --all
    * c1f1042 (HEAD, master) replacement for "amendme" commit
    | *   3c97241 (refs/stash) WIP on master: 67dec43 "amendme" commit
    | |\  
    | | * f3a50e9 index on master: 67dec43 "amendme" commit
    | |/  
    | * 67dec43 "amendme" commit
    |/  
    * 9c37840 previous commit
    * 84408ef base
    
    $ git stash apply
    git stash apply 
    Auto-merging f3
    CONFLICT (content): Merge conflict in f3
    $ git reset --hard master
    HEAD is now at c1f1042 replacement for "amendme" commit
    $ git stash apply --index
    Auto-merging f3
    CONFLICT (content): Merge conflict in f3
    Index was not unstashed.
    $ git reset --hard master
    HEAD is now at c1f1042 replacement for "amendme" commit
    
    $ git branch master-old 67dec43
    $ git log --graph --oneline --decorate --all
    * c1f1042 (HEAD, master) replacement for "amendme" commit
    | *   3c97241 (refs/stash) WIP on master: 67dec43 "amendme" commit
    | |\  
    | | * f3a50e9 index on master: 67dec43 "amendme" commit
    | |/  
    | * 67dec43 (master-old) "amendme" commit
    |/  
    * 9c37840 previous commit
    * 84408ef base
    
    $ mkdir /tmp/tt; cd /tmp/tt; git init
    ... # create files f1, f2, f3; git add ...
    $ git commit -m base
    [master 84408ef] base
     3 files changed, 3 insertions(+)
     create mode 100644 f1
     create mode 100644 f2
     create mode 100644 f3
    $ ls
    f1      f2      f3
    $ cat f1 f2 f3
    this file stays the same
    this file changes in the index
    this file changes in the WIP
    
    $ echo more for f2 >> f2; git add f2
    $ echo more for f3 >> f3
    
    $ git diff --cached
    diff --git a/f2 b/f2
    index 78991d3..3a2f199 100644
    --- a/f2
    +++ b/f2
    @@ -1 +1,2 @@
     this file changes in the index
    +more for f2
    
    $ git diff
    diff --git a/f3 b/f3
    index d5943ba..188fe9b 100644
    --- a/f3
    +++ b/f3
    @@ -1 +1,2 @@
     this file changes in the WIP
    +more for f3
    
    $ git stash
    Saved working directory and index state WIP on master: 84408ef base
    HEAD is now at 84408ef base
    $ git log --graph --oneline --decorate --all
    *   753a6c8 (refs/stash) WIP on master: 84408ef base
    |\  
    | * 36b23f2 index on master: 84408ef base
    |/  
    * 84408ef (HEAD, master) base
    
    $ git show 36b23f2
    [snip]
    diff --git a/f2 b/f2
    index 78991d3..3a2f199 100644
    --- a/f2
    +++ b/f2
    @@ -1 +1,2 @@
     this file changes in the index
    +more for f2
    
    $ git show 753a6c8
    [snip]
    diff --cc f3
    index d5943ba,d5943ba..188fe9b
    --- a/f3
    +++ b/f3
    @@@ -1,1 -1,1 +1,2 @@@
      this file changes in the WIP
    ++more for f3
    
    $ git status
    # On branch master
    nothing to commit, working directory clean
    $ git stash
    No local changes to save
    
    $ git stash pop
    ...
    $ git log --graph --oneline --decorate --all
    * 84408ef (HEAD, master) base
    
    $ git add f2
    $ git stash save --keep-index
    Saved working directory and index state WIP on master: 84408ef base
    HEAD is now at 84408ef base
    
    $ git status
    # On branch master
    # Changes to be committed:
    #   (use "git reset HEAD <file>..." to unstage)
    #
    #   modified:   f2
    #
    
    $ git log --graph --oneline --decorate --all
    *   7efe9a6 (refs/stash) WIP on master: 84408ef base
    |\  
    | * 76c840e index on master: 84408ef base
    |/  
    * 84408ef (HEAD, master) base
    $ git stash save
    Saved working directory and index state WIP on master: 84408ef base
    HEAD is now at 84408ef base
    $ git log --graph --oneline --decorate --all
    $ git lola
    *   eb383e0 (refs/stash) WIP on master: 84408ef base
    |\  
    | * aba15e6 index on master: 84408ef base
    |/  
    * 84408ef (HEAD, master) base
    
    $ git log -g --oneline refs/stash
    eb383e0 refs/stash@{0}: WIP on master: 84408ef base
    7efe9a6 refs/stash@{1}: WIP on master: 84408ef base
    
    $ git log -g --pretty=format:%H refs/stash
    
    $ git log --graph --oneline --decorate $(git log -g --pretty=format:%H refs/stash)
    *   eb383e0 (refs/stash) WIP on master: 84408ef base
    |\  
    | * aba15e6 index on master: 84408ef base
    |/  
    | *   7efe9a6 WIP on master: 84408ef base
    | |\  
    |/ /  
    | * 76c840e index on master: 84408ef base
    |/  
    * 84408ef (HEAD, master) base
    
    $ git stash pop
    # On branch master
    # 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:   f2
    #
    no changes added to commit (use "git add" and/or "git commit -a")
    Dropped refs/stash@{0} (eb383e050d150a8ce5b69a3662849ffdd7070c89)
    
    $ git stash pop
    error: Your local changes to the following files would be overwritten by merge:
        f2
    Please, commit your changes or stash them before you can merge.
    Aborting
    
    $ git reset --hard
    
    $ git stash pop --index
    # On branch master
    # Changes to be committed:
    #   (use "git reset HEAD <file>..." to unstage)
    #
    #   modified:   f2
    #
    # 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:   f3
    #
    Dropped refs/stash@{0} (7efe9a65c44156921bbbcb6a3df4edc5cb44492b)