Search code examples
gitgit-stash

How can I ensure a modified file that is stashed gets committed?


I'm using software that modifies the Changes file after publishing my distribution. This is a good thing because it reminds me to update this file (I always forget) before releasing my next version. This is fine when I do everything on the master branch.

Lately, however, I've tried to get in the habit of making changes on separate branches. So I have to stash the Changes file before I switch branches.

Is there a way to automatically pull the Changes file out of the stash when I switch back to master? If not, is there some way I can ensure it gets committed before issuing a git push?


Solution

  • I don't think you can run anything after you switched to master branch. But you can certainly set up a pre-push script to run before push on the client side.

    https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks

    The script could look into your log and see if there are any unapplied stashes