a new commit to store the tracked files that were in your working copy when you ran git stash.953ddde WIP on main: 5002d47 our new homepage |\ \ | | * 24b35a1 untracked files on main: 5002d47 our new homepage | * 7023dd4 index on main: 5002d47 our new homepage |/ * 5002d47 our new homepageĭepending on what you stashed, a single git stash operation creates either two or three new commits. Instead, you can use git stash branch to create a new branch to apply your stashed changes *. If the changes on your branch diverge from the changes in your stash, you may run into conflicts when popping or applying your stash. There is no explicit "abort" command, but hitting CTRL-C(SIGINT) will abort the stash process. Quit (any hunks that have already been selected will be stashed) You can hit ? for a full list of hunk commands. Here is the version with the emulated option -U|-unstaged: git initįor a better understanding of stashing, I think it is important to look at the states of the working tree, index and HEAD at each step. Your use case is testing before committing partial changes and it is already in the reference documentation, but with the flawed option -keep-index which creates conflicts. With a temporary file: git diff >unstaged So for the moment you have to emulate git stash push -unstaged It would be very convenient if git stash push had an option -U|-unstaged for saving only unstaged changes (to me the option -keep-index is flawed), since it has already an option -S|-staged for saving only staged changes. changes from the HEAD state, even with the option -keep-index which also sets the working tree state to the index state instead of the HEAD state (thereby creating conflicts when restoring the changes from the HEAD state with git stash pop). This command saves all changes in the working tree (staged and unstaged changes), i.e. To my knowledge, it is currently impossible to save only unstaged changes in the working tree with git stash push, i.e. incorrect) form, and git add would fail with the error message: fatal: pathspec '**/*.txt' did not match any filesĪt the stage where git stash drops the changes from the worktree, even if refs/stash has been actually updated successfully. However, in the built-in git stash, we passed the parsed (i.e. Where the original form includes the :(glob) prefix while the parsed when calling git stash - ':(glob)**/*.txt' When passing a list of pathspecs to, say, git add, we need to beĬareful to use the original form, not the parsed form of the pathspecs. (Merged by Junio C Hamano - gitster - in commit 0ba1ba4, )īuilt-in stash: handle :(glob) pathspecs again See commit 1366c78, commit 7b556aa () by Johannes Schindelin ( dscho). See commit 7db9302 () by Thomas Gummerer ( tgummerer). You can combine that with a wildcard form, for example: git stash push -all -keep-index ':(glob)**/*.testextension'īut that does not work well with Git for Windows, until Git 2.22 (Q2 2019), see issue 2037, considering git stash has been re-implemented in C (instead of a shell script) This is similar to basic git commit except the state is committed to the stash instead of current branch.Ģ019: The modern form of that command is git stash push, since Git 2.16+ ( git stash save is deprecated) Stash only the changes that are currently staged. This option is only valid for push and save commands. Or, if you want to keep saved changes in stash: git stash applyĢ022: I mention in " Stashing only staged changes in git - is it possible?", Git 2.35 (Q1 2022) comes with " git stash push -staged" ( man): You can restore the working directory as you always do like: git stash pop Then git will ask you to add or not your changes into stash. With git version 2.7.4 you may use the -patch option: git stash save -patch $ git config -global alias.stashs 'stash push -S' This alias works well to stage just the working copy changes: stash-working = "!f() from "./common/ajax" This is rarely what one wants because any interim changes to the stash are likely to result in conflicts when popping the stash later. The staged changes end up in both the stage AND the stash. However what isn't obvious is that -keep-index also stashes the staged changes. The accepted answer, and quite a few other answers, stashes the unstaged changes and leaves the stage alone as requested via -keep-index. Stashing just the working tree (unstaged changes) in Git is more difficult than it should be. Stash Without the Staged Changes The Problem with -keep-index / -k
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |