Git:如何使用存储

我试图弄清楚如何在许多未提交的更改中隐藏两个特定的文件。

这个非常有希望的答案是,将多个文件中只有一个文件用Git更改了,不会显示用法,而且在处理它时遇到问题。

以下内容不起作用,手册页也不是很有用(它似乎谈论终端输出,而不是实际存储)。 我想存储application.confplugins.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 --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产生它时,块是一个连贯的线。 要选择你将有一个单一的文件, d ecline添加帅哥,只要你达到这个文件,那么你可能会添加a从该文件LL帅哥。

你还可以通过回答这样一个问题,选择一个大块y上课。 如果大块似乎太大了,你甚至可以s PLIT它。 也可以到e DIT当前大块。


在不同的git命令中可以使用--patch -option(fe stashcommitadd )。

这是我从开发人员文档中--patch - --patch功能的详细说明:

This lets you choose one path out of a 'status' like selection.
After choosing the path, it presents the diff between the index
and the working tree file and asks you if you want to stage
the change of each hunk.  You can select one of the following
options and type return:

   y - stage this hunk
   n - do not stage this hunk
   q - quit; do not stage this hunk or any of the remaining ones
   a - stage this hunk and all later hunks in the file
   d - do not stage 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 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,?]?

不幸的是,选择文件是不可能的,只有笨蛋。

链接地址: http://www.djcxy.com/p/24509.html

上一篇: Git: how to use stash

下一篇: Stash changes to specific files