Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
git_stash [2019/02/20 16:55] – [git stash push] rpjdaygit_stash [2019/02/26 19:18] (current) – [git stash branch] rpjday
Line 19: Line 19:
 </code> </code>
  
-===== git stash push =====+===== Basic stash operations ===== 
 + 
 +==== git stash push ====
  
 Save both the unstaged and staged content in a new stash: Save both the unstaged and staged content in a new stash:
Line 42: Line 44:
   * ''%%--%%all'': Stash //all// untracked files, including ignored ones, then clean   * ''%%--%%all'': Stash //all// untracked files, including ignored ones, then clean
  
-===== git stash show =====+==== git stash show ====
  
 By default, show most recent stash: By default, show most recent stash:
Line 62: Line 64:
 </code> </code>
  
-Show the actual content:+Show the actual content with ''-p'':
  
 <code> <code>
Line 71: Line 73:
 +++ b/MAINTAINERS +++ b/MAINTAINERS
 @@ -1,3 +1,7 @@ @@ -1,3 +1,7 @@
-+unacaned stuff++uncached stuff
 + +
 + +
Line 90: Line 92:
  ============  ============
  
 +$
 +</code>
 +
 +==== git stash pop/apply ====
 +
 +Pop/apply the most recent stash, or a specified stash:
 +
 +<code>
 +$ git stash pop
 +$ git stash pop stash@{1}
 +$ git stash apply
 +</code>
 +
 +Use ''%%--%%index'' to restore the cached content in the index:
 +
 +<code>
 +$ git stash pop --index
 +</code>
 +
 +==== Throwing away stashes ====
 +
 +<code>
 +$ git stash drop
 +$ git stash drop stash@{1}
 +$ git stash clear
 +</code>
 +
 +==== Working with pathspecs ====
 +
 +''git stash push'' supports pushing partial changes using a //pathspec//:
 +
 +<code>
 +$ git stash push -- goodstuff/
 +</code>
 +
 +==== git stash branch ====
 +
 +<code>
 +Creates and checks out a new branch named <branchname>
 +starting from the commit at which the <stash> was
 +originally created, applies the changes recorded in <stash>
 +to the new working tree and index. If that succeeds, and
 +<stash> is a reference of the form stash@{<revision>}, it
 +then drops the <stash>. When no <stash> is given, applies
 +the latest one.
 +
 +This is useful if the branch on which you ran git stash
 +push has changed enough that git stash apply fails due to
 +conflicts. Since the stash entry is applied on top of the
 +commit that was HEAD at the time git stash was run, it
 +restores the originally stashed state with no conflicts.
 +</code>
 +
 +===== How stashes are implemented =====
 +
 +Stashes are represented by three new commits in the object store, referenced by stash pointers only:
 +
 +  * ''stash@{0}'': The final result, both staged and unstaged content
 +  * ''stash@{0}^1'': The base commit from which the stash is derived
 +  * ''stash@{0}^2'': Commit representing just staged content
 +
 +The //full// content of the stash:
 +
 +<code>
 +$ git diff stash@{0}^1 stash@{0}
 +diff --git a/README b/README
 +index 669ac7c32292..9c61fa8595e9 100644
 +--- a/README
 ++++ b/README
 +@@ -1,3 +1,8 @@
 ++staged stuff
 ++
 ++
 ++
 ++
 + Linux kernel
 + ============
 + 
 +@@ -16,3 +21,8 @@ several of them using the Restructured Text markup notation.
 + Please read the Documentation/process/changes.rst file, as it contains the
 + requirements for building and running the kernel, and information about
 + the problems which may result by upgrading your kernel.
 ++
 ++
 ++
 ++unstaged stuff
 ++
 +$
 +</code>
 +
 +The staged content only:
 +
 +<code>
 +$ git diff stash@{0}^1 stash@{0}^2
 +diff --git a/README b/README
 +index 669ac7c32292..ded86dccf25a 100644
 +--- a/README
 ++++ b/README
 +@@ -1,3 +1,8 @@
 ++staged stuff
 ++
 ++
 ++
 ++
 + Linux kernel
 + ============
 + 
 +$
 +</code>
 +
 +Finally, the unstaged content:
 +
 +<code>
 +$ git diff stash@{0}^2 stash@{0}
 +diff --git a/README b/README
 +index ded86dccf25a..9c61fa8595e9 100644
 +--- a/README
 ++++ b/README
 +@@ -21,3 +21,8 @@ several of them using the Restructured Text markup notation.
 + Please read the Documentation/process/changes.rst file, as it contains the
 + requirements for building and running the kernel, and information about
 + the problems which may result by upgrading your kernel.
 ++
 ++
 ++
 ++unstaged stuff
 ++
 $ $
 </code> </code>
  • git_stash.1550681720.txt.gz
  • Last modified: 2019/02/20 16:55
  • by rpjday