我怎样才能保存一个特定的文件? [英] how can I git stash a specific file?
问题描述
<强>可能重复:强>结果,
如何从多个已更改的文件中只存储一个文件
例如,如果git status给了我这个:
younker%gst
#在分支上master
#通过1次提交,你的分支领先于'origin / master'。
#
#没有为commit提交更改:
#(使用git add< file> ...更新将提交的内容)
#(使用git
#
#modified:app / controllers / cart_controller.php
#modified:app / views / cart / welcome.thtml
#
没有更改添加到提交中(使用git add和/或git commit -a)
,我只想隐藏app / views / cart / welcome.thtml,我该怎么做?就像(但当然这不起作用):
git储存保存welcome_cart app / views / cart / welcome.thtml
编辑: ,有一个命令来保存特定的路径到 git stash push -m welcome_cart app / views / cart / welcome.thtml
。
OLD ANSWER:
您可以使用 git stash --patch
(或 git stash -p
) - 您将进入交互模式,您将看到每个被更改的块。使用 n
跳过不想保存的文件,当遇到您想要保存的文件时, q
退出并保持其余的区块不分散。 a
将存储显示的大块和其他文件中的hunk。
不是用户友好的方法,但如果您确实需要它,工作就完成了。
Possible Duplicate:
How to stash only one file out of multiple files that have changed
How can I stash a specific file leaving the others currently modified out of the stash I am about to save?
For example, if git status gives me this:
younker % gst
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: app/controllers/cart_controller.php
# modified: app/views/cart/welcome.thtml
#
no changes added to commit (use "git add" and/or "git commit -a")
and I only want to stash app/views/cart/welcome.thtml, how would I do that? Something like (but of course this does not work):
git stash save welcome_cart app/views/cart/welcome.thtml
EDIT: Since git 2.13, there is a command to save a specific path to the stash: git stash push <path>
. For example: git stash push -m welcome_cart app/views/cart/welcome.thtml
.
OLD ANSWER:
You can do that using git stash --patch
(or git stash -p
) -- you'll enter interactive mode where you'll be presented with each hunk that was changed. Use n
to skip the files that you don't want to stash, y
when you encounter the one that you want to stash, and q
to quit and leave the remaining hunks unstashed. a
will stash the shown hunk and the rest of the hunks in that file.
Not the most user-friendly approach, but it gets the work done if you really need it.
这篇关于我怎样才能保存一个特定的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!