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


当前回答

由于在Git中创建分支很简单,您可以创建一个临时分支并将各个文件检入其中。

其他回答

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

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

免责声明:以下答案适用于2.13之前的git。对于2.13及以上的数字,请查看下面的另一个答案。


警告

正如评论中所指出的那样,这将所有的东西都放进了储藏室,无论是暂存的还是未暂存的。--keep索引只是在存储完成后保留索引。这可能会在以后弹出存储时导致合并冲突。


这将隐藏您以前未添加的所有内容。只需git添加要保留的内容,然后运行它。

git stash --keep-index

例如,如果要将旧提交拆分为多个变更集,可以使用以下过程:

gitrebase-i<最后一次提交>将某些更改标记为编辑。git重置HEAD^git add<您要在此更改中保留的文件>git stash—保留索引必要时修理一下。不要忘记git添加任何更改。git提交吉特藏弹根据需要,从第5步开始重复。git rebase—继续

我没有找到我需要的答案,这很简单:

git add -A
git reset HEAD fileThatYouWantToStash
git commit -m "committing all but one file"
git stash

这只存储了一个文件。

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

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

稍后执行此行

git stash—保留索引

假设你有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

你完蛋了!高温。