Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what causes git apply error already exists in working directory

Tags:

git

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?
like image 822
Mr. Avatar asked Feb 01 '26 21:02

Mr.


1 Answers

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.)
like image 191
chepner Avatar answered Feb 04 '26 10:02

chepner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!