Home > Software engineering >  what causes git apply error already exists in working directory
what causes git apply error already exists in working directory

Time:05-10

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
  1. what causes git apply to fail?
  2. 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:

  1. Delete the file, if you only need the file the patch will create.
  2. 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.)
  •  Tags:  
  • git
  • Related