Unstaged changes could not be restored due to a merge conflict

4.9k Views Asked by At

When I execute git commit -m "commit message" command, lint-staged shows this error:

enter image description here

My configuration in package.json:

"husky": {
    "hooks": {
        "pre-commit": "npm run validate && lint-staged"
    }
},
"lint-staged": {
    "*.+(js|ts|tsx)": [
        "eslint"
    ],
    "**/*.+(js|json|ts|tsx)": [
        "prettier --write"
    ]
},

It works fine on mac but windows-10 shows this error. Can anyone tell me what's going wrong with windows?

1

There are 1 best solutions below

5
On

Given the messages that are displayed : I think this hook runs

  1. git stash -k (stash everything that's not in the index)
  2. reformats the staged code, and run git add
  3. git stash pop

On your Windows machine, you happen to be in a configuration where :

  • a. you have some modifications which are not staged
  • b. these modifications conflict with the index when you reformat the index

"fixing" would be :

  • manually run git stash -k
  • create your commit (the pre-commit hook should pass without error)
  • run git stash pop
  • fix the resulting conflicts