0

If I git stash -k (stash all unstaged changes) and git pop, I get merge conflicts if one of the files was modified in the staging area and also had an unstaged change.

I'm writing a script that calls git stash -k, lints the files, and commits them if they pass. If not, I'd like to git stash pop and return the working tree to precisely its previous state.

Is this possible? Is there a merge-conflict-free way of achieving this?

Thank you!

Robert Balicki
  • 1,583
  • 2
  • 16
  • 24
  • 1
    You're going to have to solve the merge conflicts anyway. What I would do is create another branch, reset to the commit where you created the files and do a `git stash apply. Now come back to the original branch and do a `git merge --strategy='Whichever you prefer'`. Maybe you could pass the strategy as a variable.. – gran_profaci Sep 13 '15 at 03:20

1 Answers1

0

You can do it another way:

  1. Do a commit.
  2. git stash (or even better, git stash -u)
  3. Run tests.
  4. git stash pop
  5. If tests failed, undo commit with git reset --soft HEAD^
Roman
  • 6,486
  • 2
  • 23
  • 41