1

我正在与 Git 合作一个项目,由于我不需要进入的原因,我发现我可能必须对代码进行一些更改,然后将它们存储起来而不是提交它们。我有时可能需要这些更改,但不是一直需要,也不一定希望它们是永久性的。但是,这项工作可能很重要,我想尝试为自己节省一些问题。

假设我保存了多个 git stash,所以我的 stash 看起来像这样:

stash@{0}: First change
stash@{1}: Second change
...
stash@{10}: Last and final change

有没有办法在一个命令中弹出所有这些更改?或者也许将它们组合成类似的东西stash@{11}: All previous changes together

或者这甚至是一个好主意?

编辑:经过一番研究,我意识到我真的应该分支而不是以这种方式使用 git stash 。感谢您的回答!

4

2 回答 2

4

或者,也许做一个分支?分支在 Git 中很便宜,除非你告诉 Git,否则不会被推送到远程仓库。实践中的例子。

创建一个名为“my-hidden-feature”的分支:

git checkout -b my-hidden-feature

编辑和提交内容(例如,本地配置文件):

touch test.config               # Create a new file
git add test.config             # Add the new file
git commit -m "Test commit"     # Commit your hidden feature

返回到您的原始代码并做一些工作:

git checkout master             # Return to the main branch
...work here...                 # Do some work
git commit -am "Work on master" # Commit your work

哦,你需要隐藏功能吗?简单的 :

git checkout my-hidden-feature  # Go to your hidden branch
git rebase master               # Update the hidden feature with new commits from master
...do some stuff...             # Do some work on the hidden branch
git commit -am "A new hidden commit"

而且,继续!

啊,最后但并非最不重要。如果你是在命令行工作,我强烈推荐像oh-my-zsh这样的工具,它有一个可以在你的终端中显示当前分支的插件。如果你不想迷失在 Git 的边缘,非常非常有用。

于 2012-12-05T16:23:54.073 回答
3

你严重滥用了藏匿处。藏匿处只不过是一个隐藏的一次性分支。git stash save做这个:

git checkout -b stashbranch
git add -A
git commit -m "stashentry"
git checkout -

git stash apply做类似的事情:

git cherry-pick *stashcommit*
git reset HEAD^

如果您了解这些命令的作用,则无需将 stash 用于这种情况下的复杂设备。

您是否有理由不使用分支?

于 2012-12-05T16:34:04.867 回答