La syntaxe de votre utilisation de git diff
est
git diff [--no-index] <path> <path>
Dans votre cas, le --no-index
est supposé implicitement. Par conséquent, la commande
git diff a b
suppose que b
est une version plus récente du fichier a
. L'exécution de vos commandes produit un patch qui ressemble à ceci:
$ git diff --no-index 123.txt 456.txt
diff --git a/123.txt b/456.txt
index 97f93f4..9fa0bac 100644
--- a/123.txt
+++ b/456.txt
@@ -1 +1 @@
-123.txt
+456.txt
Si vous essayez de le faire avec plus de 2 fichiers, il y a une erreur:
$ git diff -- 123.txt 456.txt 789.txt
Not a git repository
To compare two paths outside a working tree:
usage: git diff [--no-index] <path> <path>
$ git diff --no-index 123.txt 456.txt 789.txt
usage: git diff --no-index <path> <path>
Une solution de contournement (en supposant que vous voulez créer un correctif à la fois a
et b
ajouté) serait de créer un nouveau repo git dans un répertoire temporaire. . Vous pouvez créer un commit initial sans fichiers à l'aide
git commit --allow-empty -m "Initial"
et copiez les fichiers a
et b
dans
Après l'exécution git add --all
, git diff --staged > test.patch
va créer un patch adapté, comme celui-ci:
diff --git a/123.txt b/123.txt
new file mode 100644
index 0000000..97f93f4
--- /dev/null
+++ b/123.txt
@@ -0,0 +1 @@
+123.txt
diff --git a/456.txt b/456.txt
new file mode 100644
index 0000000..9fa0bac
--- /dev/null
+++ b/456.txt
@@ -0,0 +1 @@
+456.txt
diff --git a/789.txt b/789.txt
new file mode 100644
index 0000000..a25ef22
--- /dev/null
+++ b/789.txt
@@ -0,0 +1 @@
+789.txt
Quelle est la sortie de 'git status' avant et après l'application du patch? – rlee827
@ rlee827 Je ne le fais pas dans un dépôt. – timakro