git 一次应用多个存储

标签 git git-commit git-stash

我有两次存储,我需要在一次提交中提交两次存储。

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

error: Your local changes to the following files would be overwritten by merge:
        library/HQ/groupsql.sql
Please commit your changes or stash them before you merge.
Aborting
The stash entry is kept in case you need it again.

如何 pop 两个存储然后提交它们。

最佳答案

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

// 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

底线,每个存储应用一旦完成就会在本地分支上生成提交,但只要更改是本地的(而不是推送),您就可以更改历史记录

我建议您也阅读This thread ,它包含一些巧妙的技巧,自 git 2.11 起可用:你可以使用 git stash apply n而不是git stash apply stash@{n}

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

不过,我从未见过在一个命令中执行此操作的功能。所以现在我的答案是“不,你不能一次应用多个存储”。我很高兴能得到更有经验的 git 用户的证明。

关于git 一次应用多个存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58926699/

相关文章:

android - 在任何商店部署基于 API 的应用程序

Git 重置(不难)然后快进 merge 某些提交

git - svn update 与 git pull - 实现细节

github - GitHub 提交消息中的图形

git - Jenkins 无效的 Git 修订

git - 应用 git stash 时如何忽略空格?

git - 在 merge 到 master 之前我如何在其他分支上工作?

bitbucket - 通过注释格式强制 Bitbucket Commit 与 JIRA Ticket 相关联

git stash 无法应用保存的更改