Git stash files by name9/2/2023 ![]() ![]() Otherwise, between -a and -u, whichever one is set last is retained.Īt this point the script creates either one or two commits: It is incompatible with -a and -u and will error-out if any of those are given. Using -p, for instance, completely changes the algorithm the script uses to build the stash, and also turns on -keep-index, forcing you to use -no-keep-index to turn it off if you don't want that. ![]() Some of these imply, override, or disable others. There seems to be no particular reason for this, it's just how the script does things, but it explains why the "arrows" (lines) are as they are in the diagram.) The various options at save timeĪt save time, you can specify any or all of the following options: (It's not actually important, as far as I can tell, but I'll add here that i has C as a parent commit, while u is a parentless, or root, commit. In this case, stash is commit w, stash^ is commit C (still also HEAD), stash^2 is commit i, and stash^3 is commit u, which contains the "untracked" or even "untracked and ignored" files. (these diagrams really need to be images so that they can have arrows, rather than ASCII-art where arrows are tough to include). With -untracked or -all there's a third parent for w, so the diagram looks more like this: o-o-C <- HEAD (Not shown, because it's just hard to diagram, is the fact that w's first parent is C and its second parent is i.) The stash bag itself is the little triangular bag hanging from C, and it contains two commits: w is the work-tree commit and i is the index commit. Node C (for Commit) has a letter so we can name it: it's where the "stash bag" hangs from. The os are any old ordinary commit nodes, as is C. When you use git stash save with either -u or -a, the stash script writes its "stash bag" as a three-parent commit rather than the usual two-parent commit.ĭiagrammatically, the "stash bag" normally looks like this, in terms of the commit graph: o-o-C <- HEAD (typically, a branch) ![]() Note that there is no option to skip the untracked and/or ignored files in a stash. To see why, look at step 3 in the "apply" description. Remember, the files that git clean removes are precisely those that you can't get back from Git!) (If so, you should move them outside your work-tree instead of git clean-ing them away. This means running git clean -f, or even git clean -fdx, which is kind of an ugly thing to have to do, since some of the untracked or untracked-and-ignored files/directories may be items you want to keep, rather than deleting entirely. I use the latter one to split my daily work into atomic commits.You need the directory to be clean (in git clean terms) for the stash to apply properly. If you're interested in a more comfortable way to handle this task, you may also take a look on git gui tools like LazyGit or gitui. S - split the current hunk into smaller hunks ![]() K - leave this hunk undecided, see previous hunk K - leave this hunk undecided, see previous undecided hunk J - leave this hunk undecided, see next hunk J - leave this hunk undecided, see next undecided hunk search for a hunk matching the given regex Q - quit do not stage this hunk or any of the remaining onesĪ - stage this hunk and all later hunks in the fileĭ - do not stage this hunk or any of the later hunks in the file This is the detailed explanation of the -patch-function, which i grabbed from the developers documentation: This lets you choose one path out of a 'status' like selection.Īfter choosing the path, it presents the diff between the indexĪnd the working tree file and asks you if you want to stage Using the -patch-option is possible on different git commands (f.e. It is also possible to edit the current hunk. If the hunk seems to be too big, you even might split it. You're also able to choose a single hunk by answering the question with yes. To select a single file you'll have to decline adding hunks as long as you reach that file, then you might add all hunks from that file. Git will then show a dialog like the following, for every hunk in your possible commit: diff -git files over filesĪ hunk is a coherent diff of lines as git-diff produces it. " to discard changes in working directory)Īpp (master)$ git stash -p. (use "git push" to publish your local commits) Your branch is ahead of 'origin/master' by 29 commits. I want to stash nf and plugins.sbt and then commit everything else. The following doesn't work and the man page isn't very helpful (it appears to talk about terminal output, not actually stashing). This very promising answer, Stash only one file out of multiple files that have changed with Git?, doesn't show the usage and I'm having trouble working it out. I'm trying to figure out how to stash two specific files among many uncommitted changes. ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |