Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
git一次应用多个存储_Git_Git Commit_Git Stash - Fatal编程技术网

git一次应用多个存储

git一次应用多个存储,git,git-commit,git-stash,Git,Git Commit,Git Stash,我藏了两次,我需要在一次提交中提交两次 我使用git stash apply来应用最新的隐藏,但是当我再次使用它时,它会抛出下面的错误 如何弹出这两个隐藏,然后提交它们。我认为您可以执行以下操作: // to see the list of "stashes" (like every time when stash run 'git stash' a new entry is created in the list > git stash list // Lest assume you

我藏了两次,我需要在一次提交中提交两次

我使用
git stash apply
来应用最新的隐藏,但是当我再次使用它时,它会抛出下面的错误


如何弹出这两个隐藏,然后提交它们。

我认为您可以执行以下操作:

// to see the list of "stashes" (like every time when stash run 'git stash' a new entry is created in the list
> git stash list

// Lest assume you need stash@{1} and stash@{3} for the sake of example

> git stash apply stash@{1} 
git commit -am "Whatever message"

> git stash apply stash@{3}
git commit --amend  // to add changes from stash3 from the previous commit
底线是,每个stash apply一旦完成就会在本地分支上生成commit,但是您可以更改历史记录,只要更改是本地的(而不是推送的)

我建议您也阅读一下,它包含一些简洁的技巧,从git 2.11开始就可以使用:您可以使用
git stash apply n
而不是
git stash apply stash@{n}

另一个建议:您可以使用
git stash show stash@{3}
查看在stash 3中更改了哪些文件(如果您不确定要应用哪个存储)


不过,我从未见过在一个命令中执行此操作的特性。所以现在我的答案是“不,不能同时应用多个隐藏”。我很高兴被更有经验的git用户证明不是这样

我认为你不可能一次就做到这一点,当然,除非你已经准备好编写自己的脚本。原因是,您当前的头部和两个隐藏处可能有重叠的更改。即使您为自己编写了一个脚本,您也很难解决冲突,因为您的脚本不知道保留哪些更改和放弃哪些更改。因此,正确的方法是按书来做,即:

git stash apply stash@{1}
# resolve conflicts if any
git add .
git commit -m "<commit_message>"
git stash apply stash@{2}
git stash apply stash@{1}
#解决任何冲突(如果有)
git添加。
git提交-m“”
git stash apply stash@{2}

readthis@abby37它使每个隐藏都成为一个提交。在您运行第一个隐藏应用程序之后,您将向给定的提交添加一个文件,然后再次运行隐藏应用程序,然后向给定的提交添加文件。因此,所有这些隐藏更改都将通过使用git commit在给定的commit中提交——请注意,一次性提交是可能的。不要尝试像这样组合多个存储。只需应用一个并提交,然后应用下一个并提交,然后使用
git-rebase-i
挤压两个提交。OP想要在单个命令中完成这一操作,为此他必须编写自己的自定义命令。是吗?我相信是的,OP必须为此创建一个自定义脚本,但再次强调,如果存储之间存在冲突(这可能会发生),则必须以某种方式解决(可能是手动解决)
git stash apply stash@{1}
# resolve conflicts if any
git add .
git commit -m "<commit_message>"
git stash apply stash@{2}