如何在我的分支中只存储多个已更改文件中的一个?
当前回答
您可以简单地执行以下操作:
git stash push "filename"
或带有可选消息
git stash push -m "Some message" "filename"
其他回答
这里的每个答案都很复杂。。。
“藏起来”怎么样
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 filepath”添加文件。
稍后执行此行
git stash—保留索引
我没有找到我需要的答案,这很简单:
git add -A
git reset HEAD fileThatYouWantToStash
git commit -m "committing all but one file"
git stash
这只存储了一个文件。
git stash push -p -m "my commit message"
-p让我们选择应该隐藏的大块;也可以选择整个文件。
系统将提示您对每个大块执行一些操作:
y - stash this hunk
n - do not stash this hunk
q - quit; do not stash this hunk or any of the remaining ones
a - stash this hunk and all later hunks in the file
d - do not stash this hunk or any of the later hunks in the file
g - select a hunk to go to
/ - search for a hunk matching the given regex
j - leave this hunk undecided, see next undecided hunk
J - leave this hunk undecided, see next hunk
k - leave this hunk undecided, see previous undecided hunk
K - leave this hunk undecided, see previous hunk
s - split the current hunk into smaller hunks
e - manually edit the current hunk
? - print help
一个复杂的方法是首先提交所有内容:
git add -u
git commit // creates commit with sha-1 A
重置回原始提交,但从新提交中签出_one_file:
git reset --hard HEAD^
git checkout A path/to/the_one_file
现在,您可以存储_one_file:
git stash
通过将提交的内容保存在文件系统中并重置为原始提交来进行清理:
git reset --hard A
git reset --soft HEAD^
是的,有点尴尬。。。
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的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之间的区别