temp commits are generally more useful than git stash.

instead of stashing, do a commit with a message like "THIS IS NOT A COMMIT, DON'T INCLUDE THIS". with some discipline you can then go back to your branch, `git reset --soft HEAD~1` and voila, it's similar to a `git stash pop`.

but it's better because you can do this in multiple branches at the same time and there's no fear of accidentally dropping some stashed commit.

  • 3
    Or you could also just use apply which won't remove the stash and you can also specify which stash you want to apply. It doesn't need to be the top. Your solution seems more complex than necessary
  • 1
    Truth. Reset soft is my most common rebase flatten method. Stashing is mostly meant for intermediary cleanup or relocation.

    You can also do a ninja merge like:
    Git commit-tree currentbranch^{tree} -p targetbranch -m message && git merge --ff-only
    Advantage to that is it can be applied recursively over any number of features.
  • 1
    @don-rager curiously I feel that your solution is the one that is more complex:

    git stash is basically a "global" list for all your temp commits. why would you ever keep temp commits from different branches in the same global list? it's pointless.

    let's say you stash commit 1 from branch A. are you ever going to apply commit 1 in branch B? no! not in a million years! why would you then keep all your temp commits together in a shared global list? it makes no sense.

    that is still a problem at a concept level even if you use stash apply.

    but yeah, let's use stash apply instead of stash pop so now you get to have dozens of old stashes that you have to clean up.

    i only see point for git stash as one offs for work in the same branch: you're doing some changes but it's becoming a pretty big commit. so what do you do? you stash, then write a small part, commit, pop stash. and so on until there's nothing to stash. it's very effective for that.
  • 0
    @don-rager also, you can create stash commits without a name which enables the bad practice of not knowing what the fuck some nameless stash commit does.

    commits do not have that problem.
  • 1
    @jesustricks you can also create commits without a message if you desire
Add Comment