Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git:如何使用stash-p来隐藏特定的文件?_Git_Git Stash - Fatal编程技术网

Git:如何使用stash-p来隐藏特定的文件?

Git:如何使用stash-p来隐藏特定的文件?,git,git-stash,Git,Git Stash,我试图找出如何在许多未提交的更改中隐藏两个特定的文件 这个非常有希望的答案,没有显示它的用法,我很难找到它 以下内容不起作用,手册页也没有太大帮助—它似乎是在讨论终端输出,而不是实际隐藏。我想隐藏application.conf和plugins.sbt,然后提交所有其他内容 app (master)$ git status On branch master Your branch is ahead of 'origin/master' by 29 commits. (use "git pus

我试图找出如何在许多未提交的更改中隐藏两个特定的文件

这个非常有希望的答案,没有显示它的用法,我很难找到它

以下内容不起作用,手册页也没有太大帮助—它似乎是在讨论终端输出,而不是实际隐藏。我想隐藏application.conf和plugins.sbt,然后提交所有其他内容

app (master)$ git status
On branch master
Your branch is ahead of 'origin/master' by 29 commits.
  (use "git push" to publish your local commits)

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   views/mobile/blog.scala.html
        modified:   views/mobile/slideshow.scala.html
        modified:   ../public/css/mobile/styles.css

Unmerged paths:
  (use "git reset HEAD <file>..." to unstage)
  (use "git add <file>..." to mark resolution)

        both modified:   ../conf/application.conf

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:   ../project/plugins.sbt

app (master)$ git stash -p ../conf/application.conf ../project/plugins.sbt 

usage: git stash list [<options>]
   or: git stash show [<stash>]
   or: git stash drop [-q|--quiet] [<stash>]
   or: git stash ( pop | apply ) [--index] [-q|--quiet] [<stash>]
   or: git stash branch <branchname> [<stash>]
   or: git stash [save [--patch] [-k|--[no-]keep-index] [-q|--quiet]
                       [-u|--include-untracked] [-a|--all] [<message>]]
   or: git stash clear
使用不带参数的git stash-p。然后,您将能够以交互方式选择要隐藏的更改:

diff --git a/test b/test
index acbd8ae..662d47a 100644
--- a/test
+++ b/test
@@ -10,6 +10,7 @@ test
(...)
+    test
(...)
Stash this hunk [y,n,q,a,d,/,e,?]?
不幸的是,无法选择文件,只能选择大块头。

使用

git stash --patch
git随后将为您可能提交的每个大块头显示如下对话框:

diff --git files over files
index e69de29..ac4f3b3 100644
--- a/file.txt
+++ b/file.txt
@@ -0,0 +1 @@
+you did awesome stuff!
Stash this hunk [y,n,q,a,d,/,e,?]?
一个大块头是git diff生成的一组连贯的线。要选择单个文件,您必须拒绝添加大块,只要您到达该文件,然后您可以添加该文件中的所有大块

你也可以通过回答“是”来选择一个帅哥。如果这个大块头看起来太大,你甚至可以把它分开。也可以编辑当前的帅哥

可以在不同的git命令上使用-patch选项,例如stash、commit和add

这是对-patch函数的详细解释,我从


如果您对一种更舒适的方式来处理此任务感兴趣,您还可以看看git gui工具,如。我用它将日常工作分解为原子提交。

在最新版本的>v2.13中,您可以使用

git stash push -- <pathspec>
您可以通过使用全局模式将特定文件隐藏在路径中,从而节省键入的时间

git stash push -- **/path/**

您将只希望暂存您要隐藏的文件,因为任何其他暂存文件都将与特定文件一起隐藏,但在隐藏后也将保持暂存状态,因此如果git stash pop,您将遇到冲突。

为什么这不是最重要的答案?
git stash push -- example/file/path/and/file.html
git stash push -- **/path/**