我怎样才能存储特定文件? [重复]

本文翻译自:How can I git stash a specific file? [duplicate]

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: 例如,如果git status给我这个:

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? 我只想藏匿app / views / cart / welcome.thtml,我该怎么做? Something like (but of course this does not work): 有点像(但当然这不起作用):

git stash save welcome_cart app/views/cart/welcome.thtml

#1楼

参考:https://stackoom.com/question/N6Rv/我怎样才能存储特定文件-重复


#2楼

I usually add to index changes I don't want to stash and then stash with --keep-index option. 我通常添加索引更改,我不想隐藏,然后使用--keep-index选项存储。

git add app/controllers/cart_controller.php
git stash --keep-index
git reset

Last step is optional, but usually you want it. 最后一步是可选的,但通常你想要它。 It removes changes from index. 它从索引中删除更改。


Warning As noted in the comments, this puts everything into the stash, both staged and unstaged. 警告正如评论中所述,这会将所有内容都放入存储中,无论是暂存还是非暂存。 The --keep-index just leaves the index alone after the stash is done. 在保存完成后,--keep-index只保留索引。 This can cause merge conflicts when you later pop the stash. 以后弹出存储时,这可能会导致合并冲突。


#3楼

EDIT: Since git 2.13, there is a command to save a specific path to the stash: git stash push <path> . 编辑:从git 2.13开始,有一个命令可以保存存储的特定路径: 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. 你可以使用git stash --patch (或git stash -p )来做到这一点 - 你将进入交互模式,在那里你将看到每个被更改的大块。 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. 使用n跳过你不想藏匿,文件y当你遇到要藏匿的一个,并且q退出并离开unstashed剩余的帅哥。 a will stash the shown hunk and the rest of the hunks in that file. a将隐藏显示的大块和其余的帅哥放在该文件中。

Not the most user-friendly approach, but it gets the work done if you really need it. 这不是最用户友好的方法,但如果你真的需要它,它可以完成工作。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值