如何在我的分支中只存储多个已更改文件中的一个?


当前回答

假设你有3个文件

a.rb
b.rb
c.rb

你只想藏b.rb和c.rb,而不想藏a.rb

你可以这样做

# commit the files temporarily you don't want to stash
git add a.rb
git commit -m "temp" 

# then stash the other files
git stash save "stash message"

# then undo the previous temp commit
git reset --soft HEAD^
git reset

你完蛋了!高温。

其他回答

当您尝试在两个分支之间切换时,会出现这种情况。

尝试使用“git add filepath”添加文件。

稍后执行此行

git stash—保留索引

如果不想指定包含隐藏更改的消息,请在双破折号后传递文件名。

$ git stash -- filename.ext

如果它是一个未跟踪的/新的文件,则必须先将其暂存。

此方法适用于git2.13版本+

万一你真的打算在使用git stash时丢弃更改(而不是真的使用git stash临时存储),那么你可以使用

git checkout -- <file>

[注]

这个git存储只是分支和执行任务的一个快速而简单的替代方案。

您可以简单地执行以下操作:

git stash push "filename"

或带有可选消息

git stash push -m "Some message" "filename"

类似的情况。做了承诺,意识到这不好。

git commit -a -m "message"
git log -p

根据这些回答,这对我有帮助。

# revert to previous state, keeping the files changed
git reset HEAD~
#make sure it's ok
git diff
git status
#revert the file we don't want to be within the commit
git checkout specs/nagios/nagios.spec
#make sure it's ok
git status
git diff
#now go ahead with commit
git commit -a -m "same|new message"
#eventually push tu remote
git push