Unstaged changes could not be restored due to a merge conflict
Asked Answered
C

1

6

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?

Curst answered 10/12, 2020 at 7:22 Comment(1)
run "git status" after your hook has runArmistice
A
5

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
Armistice answered 10/12, 2020 at 8:20 Comment(6)
Thanks for the info. But I can confirm you there is no conflict in my repository. I have cleaned/reset my full repository, but the error doesn't go away from windows.Curst
@Arif: updated the "fixing" paragraph in my answerArmistice
To debug your issue, you can run the actions manually : what do you get if you run npm run validate from your repo's root directory ? and lint-staged ?Armistice
As soon as I changed npm to yarn like npm run validate && lint-staged to yarn validate && lint-staged it start working.Curst
hmmm, so it looks like a javascript issue, and probably versions of packages not exactly the same on both machines. Well, since you fixed it, I guess you won't need to dig deeper into how it works.Armistice
Idk why I had to commit my package.json file changes in a separate commit and workedMozellemozes

© 2022 - 2024 — McMap. All rights reserved.