如何在我的分支中只存储多个已更改文件中的一个?
当前回答
我会使用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
这里的每个答案都很复杂。。。
“藏起来”怎么样
git diff /dir/to/file/file_to_stash > /tmp/stash.patch
git checkout -- /dir/to/file/file_to_stash
这将弹出文件更改:
git apply /tmp/stash.patch
与隐藏一个文件并将其弹出完全相同的行为。
git add . //stage all the files
git reset <pathToFileWillBeStashed> //unstage file which will be stashed
git stash //stash the file(s)
git reset . // unstage all staged files
git stash pop // unstash file(s)
由于在Git中创建分支很简单,您可以创建一个临时分支并将各个文件检入其中。
如果不想指定包含隐藏更改的消息,请在双破折号后传递文件名。
$ git stash -- filename.ext
如果它是一个未跟踪的/新的文件,则必须先将其暂存。
此方法适用于git2.13版本+
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的git添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- Git拉另一个分支
- 在Bash命令提示符上添加git分支
- 如何更改Git日志日期格式
- git pull -rebase和git pull -ff-only之间的区别