Подтвердить что ты не робот

Git: как использовать stash -p для хранения определенных файлов?

Я пытаюсь выяснить, как хранить два определенных файла среди многих незафиксированных изменений.

Этот очень многообещающий ответ Выложите только один файл из нескольких файлов, которые были изменены с помощью Git?, не показывает использование, и я имею проблема работа с этим.

Следующие действия не работают, и справочная страница не очень полезна (она, по-видимому, говорит о выходе терминала, а не о том, что она вообще застревает). Я хочу занести 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
4b9b3361

Ответ 1

Использование

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,?]?

Колонка представляет собой когерентный diff строк, поскольку git -diff производит его. Чтобы выбрать один файл, вам нужно будет d ecline добавлять hunks до тех пор, пока вы достигнете этого файла, тогда вы можете добавить a ll hunks из этого файла.

Вы также можете выбрать один кусок, ответив на вопрос с помощью y es. Если кусок кажется слишком большим, вы даже можете s его использовать. Также возможно e dit текущего hunk.


Использование --patch -option возможно при разных командах git (f.e. stash, commit и add).

Это подробное объяснение функции --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

Ответ 2

Используйте 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,?]?

К сожалению, невозможно выбрать файлы, только куски.