简体   繁体   中英

git apply can apply multiple times if no lines are removed

I have the following patch

diff --git a/.htaccess b/.htaccess
index 4298b10..aa3d50d 100644
--- a/.htaccess
+++ b/.htaccess
@@ -364,6 +364,15 @@
             Require all denied
         </IfVersion>
     </Files>
+    <Files patches>
+        <IfVersion < 2.4>
+            order allow,deny
+            deny from all
+        </IfVersion>
+        <IfVersion >= 2.4>
+            Require all denied
+        </IfVersion>
+    </Files>

 # For 404s and 403s that aren't handled by the application, show plain 404 response
 ErrorDocument 404 /pub/errors/404.php

When I use git apply a 2nd time the patch does not fail to apply, instead it just appends it at the same line. Is there any way to prevent this from happening?

Also when I use git apply -R it will remove one of the added instances.

The short answer is no: git apply treats the incoming change as a patch, and merely needs to find the correct context. As long as the context continues to match—and it does in this case—the patch continues to apply.

This is one reason, perhaps the main one, to avoid using patches. A git cherry-pick has more information available to it and will not re-apply the change.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM