i am trying to apply a commit from one repository and apply it on other repository. to do so, i am using git show
to generate the git patch\diff then pipe it to git apply
. for some commits, the following error pops
$ git show <hash> | git -C ../other/repo apply
error: .foo.txt: already exists in working directory
- what causes
git apply
to fail? - how can it be fixed?
CodePudding user response:
git apply
generally doesn't try to resolve conflicts. You appear to have a .foo.txt
file that already exists, and the patch expects to create one, not modify an existing gone.
You can try the following:
- Delete the file, if you only need the file the patch will create.
- Rename the file, and after the patch is applied, manually resolve any differences between the "new"
.foo.txt
and your preexisting one. (This may require an additional commit if you make any changes.)