test_expect_success 'stash with multiple pathspec arguments' '>foo &&>bar &&>extra &&git add foo bar extra &&
git stash push -- foo bar &&
test_path_is_missing bar &&test_path_is_missing foo &&test_path_is_file extra &&
git stash pop &&test_path_is_file foo &&test_path_is_file bar &&test_path_is_file extra
# revert to previous state, keeping the files changedgit reset HEAD~#make sure it's okgit diffgit status#revert the file we don't want to be within the commitgit checkout specs/nagios/nagios.spec#make sure it's okgit statusgit diff#now go ahead with commitgit commit -a -m "same|new message"#eventually push tu remotegit push
#!/bin/sh
# first, go to the root of the git repocd `git rev-parse --show-toplevel`
# create a commit with only the stuff in stagingINDEXTREE=`git write-tree`INDEXCOMMIT=`echo "" | git commit-tree $INDEXTREE -p HEAD`
# create a child commit with the changes in the working treegit add -AWORKINGTREE=`git write-tree`WORKINGCOMMIT=`echo "" | git commit-tree $WORKINGTREE -p $INDEXCOMMIT`
# get back to a clean state with no changes, staged or otherwisegit reset -q --hard
# Cherry-pick the index changes back to the index, and stash.# This cherry-pick is guaranteed to succeedgit cherry-pick -n $INDEXCOMMITgit stash
# Now cherry-pick the working tree changes. This cherry-pick may fail# due to conflictsgit cherry-pick -n $WORKINGCOMMIT
CONFLICTS=`git ls-files -u`if test -z "$CONFLICTS"; then# If there are no conflicts, it's safe to reset, so that# any previously unstaged changes remain unstaged## However, if there are conflicts, then we don't want to reset the files# and lose the merge/conflict info.git reset -qfi
y - stash this hunkn - do not stash this hunkq - quit; do not stash this hunk or any of the remaining onesa - stash this hunk and all later hunks in the filed - do not stash this hunk or any of the later hunks in the fileg - select a hunk to go to/ - search for a hunk matching the given regexj - leave this hunk undecided, see next undecided hunkJ - leave this hunk undecided, see next hunkk - leave this hunk undecided, see previous undecided hunkK - leave this hunk undecided, see previous hunks - split the current hunk into smaller hunkse - manually edit the current hunk? - print help
# commit the files temporarily you don't want to stashgit add a.rbgit commit -m "temp"
# then stash the other filesgit stash save "stash message"
# then undo the previous temp commitgit reset --soft HEAD^git reset
# Save everythinggit stash
# Re-apply everything, but keep the stashgit stash apply
git checkout <"files you don't want in your stash">
# Save only the things you wanted savedgit stash
# Re-apply the original state and drop it from your stashgit stash apply stash@{1}git stash drop stash@{1}
git checkout <"files you put in your stash">
git add . //stage all the filesgit reset <pathToFileWillBeStashed> //unstage file which will be stashedgit stash //stash the file(s)git reset . // unstage all staged filesgit stash pop // unstash file(s)
Command Descriptiony stash this hunk/ search for a hunk by regex .? help .n don't stash this hunk .q quit (any hunks that have already been selected will be stashed) .s split this hunk into smaller hunks