2014-05-16 9 views
11

Ich versuche herauszufinden, wie zwei bestimmte Dateien unter vielen nicht festgeschriebenen Änderungen gespeichert werden.Git: Wie stash -p zum Speichern bestimmter Dateien verwenden?

Diese viel versprechende Antwort, Stash only one file out of multiple files that have changed with Git?, zeigt nicht die Verwendung und ich habe Probleme, es zu erarbeiten.

Das Folgende funktioniert nicht und die Manpage ist nicht sehr hilfreich (es scheint über Terminalausgabe zu sprechen, nicht wirklich Verstecke). Ich möchte application.conf und plugins.sbt verstecken und dann alles andere übernehmen.

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 

Antwort

18

Verwenden

git stash --patch 

git zeigt dann einen Dialog, wie die folgenden, für jeden Mann an Ihrer Seite möglich begehen:

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

Ein großes Stück ist ein kohärentes diff von Zeilen wie git-diff erzeugt es. Um eine einzelne Datei auszuwählen, musst du d eccline hinzufügen, solange du diese Datei erreichst, dann kannst du a ll hunks aus dieser Datei hinzufügen.

Sie können auch ein einzelnes Stück auswählen, indem Sie die Frage mit y es beantworten. Wenn das Stück zu groß zu sein scheint, könnte es sogar s plit it. Es ist auch möglich, e dit das aktuelle Stück.


die --patch -option Verwendung ist möglich, auf verschiedene Befehle GIT (F.E. stash, commit und add).

Dies ist die detaillierte Erklärung der --patch -function, die ich aus dem developers documentation packte:

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 
+1

oder git stash -p – Matthias

5

Verwenden Sie git stash -p ohne Argumente. Sie werden dann in der Lage sein, interaktiv Änderungen auszuwählen, die Sie verstauen wollen:

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

Leider möglich ist es nicht Dateien auswählen, nur große Stücke.