¿Hay alguna forma de hacer que Git marque un archivo como en conflicto?


Es posible confirmar archivos que contienen datos de conflicto. ¿Hay alguna forma de marcar estos archivos como en conflicto de nuevo, para que al ejecutar git mergetool se generen los archivos necesarios y se ejecute la herramienta merge?

Author: Christian Neverdal, 2010-05-06

6 answers

Puede obtener el contenido del archivo con marcadores de conflicto usando git checkout --conflict=merge -- file, pero si ha limpiado el índice usando git add file (o si GUI lo hizo por usted) no funcionaría.

Existe git update-index --unresolve, pero es hacky, y no funciona muy confiablemente. Creo que el estado que restaura no sería suficiente para git-mergetool.

Probablemente tendría que rehacer merge, o usar git update-index --cacheinfo para configurar manualmente la versión de stages... git-stash puede ayudarte a preservar los conflictos correctamente resueltos.

 17
Author: Jakub Narębski,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-05-07 01:17:57

Si el índice ya está en un estado de conflicto, simplemente revise el archivo con la bandera --conflict=merge:

git checkout --conflict=merge file

Si el índice está limpio porque el archivo no resuelto se ha agregado [erróneamente], simplemente resetéelo antes de comprobarlo:

git reset file
git checkout --conflict=merge file

Esto le permitirá reanudar la resolución de conflictos normalmente (por ejemplo, git mergetool).

NOTA: Promover un comentario a la respuesta de @jakub-narębski en su propia respuesta por solicitud de @fourpastmidnight. :)

 12
Author: Gingi,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-05-18 16:37:15

La solución más elegante sería prevenir este problema desde el principio:
git config --global mergetool.[tool].cmd [command-line call]
git config --global mergetool.[tool].trustExitCode false

 5
Author: Christian Neverdal,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-05-18 15:08:17

Por lo que sé, no podrá confirmar mientras un archivo todavía contenga marcadores de conflicto.... lo cual no es exactamente cierto:
El OP menciona que puedes (copio aquí su pastbin ), pero eso no será suficiente para que la mergetool se active de nuevo:

Auto-merged README
CONFLICT (content): Merge conflict in README
Automatic merge failed; fix conflicts and then commit the result.
lynx:~/test_clone$ ls
README
lynx:~/test_clone$ git add README
lynx:~/test_clone$ git commit -a
Created commit 46ee062: It works!
lynx:~/test_clone$ ls
README
lynx:~/test_clone$ cat README
<<<<<<< HEAD:README
testingtesting
=======
hmm
>>>>>>> 881d60f5f738bc5716f5c9a9384e262b535717fd:README
lynx:~/test_clone$

Como Charles Bailey comenta, e ilustra en esto ASÍ responde, la mergetool es consultada porque hay 3 instancias del mismo archivo en el índice:

Para un archivo no mezclado en un conflicto, git pone a disposición las versiones base común, local y remota del archivo en el índice. (Aquí es donde se leen para su uso en una herramienta de diff de 3 vías por git mergetool.) Puedes usar git show para verlos:

# common base:
git show :1:afile.txt

# 'ours'
git show :2:afile.txt

# 'theirs'
git show :3:afile.txt

git add (con cualquier contenido, incluyendo marcadores de conflicto) elimina automáticamente 2 de ellos, asegurando la mergetool no se volverá a llamar.

 2
Author: VonC,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 11:33:15

@VonC: Al principio no creé una cuenta (ahora la tengo), así que no pude publicar un comentario. Invocar git mergetool no lo detecta, parece:

Auto-merged README
CONFLICT (content): Merge conflict in README
Automatic merge failed; fix conflicts and then commit the result.
lynx:~/test_clone$ ls
README
lynx:~/test_clone$ git add README
lynx:~/test_clone$ git commit -a
Created commit 46ee062: It works!
lynx:~/test_clone$ ls
README
lynx:~/test_clone$ cat README
>>>>>> 881d60f5f738bc5716f5c9a9384e262b535717fd:README
lynx:~/test_clone$ git mergetool
merge tool candidates:  opendiff emerge vimdiff
No files need merging
lynx:~/test_clone$

Git mergetool puede aceptar un nombre de archivo, pero eso tampoco funciona:

Auto-merged README
CONFLICT (content): Merge conflict in README
Automatic merge failed; fix conflicts and then commit the result.
caracal:~/test_clone2$ git mergetool
merge tool candidates:  opendiff emerge vimdiff
Merging the files: README

Normal merge conflict for 'README':
  {local}: modified
  {remote}: modified
Hit return to start merge resolution tool (emerge): 
caracal:~/test_clone2$ ls
#*merge*#145962bz#  README  README~  README.orig
caracal:~/test_clone2$ git mergetool
merge tool candidates:  opendiff emerge vimdiff
No files need merging
caracal:~/test_clone2$ git mergetool README
merge tool candidates:  opendiff emerge vimdiff

README: file does not need merging
caracal:~/test_clone2$ ls
#*merge*#145962bz#  README  README~  README.orig
caracal:~/test_clone2$ 

Tenga en cuenta aquí también que no confirmé después de salir de git mergetool.

 1
Author: Christian Neverdal,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-05-06 22:00:50

Utilice git update-index --unresolve

Desde git 1.7 utiliza la información resolve-undo del índice para restaurar las 3 etapas (1:base, 2:la nuestra, 3: la suya): https://github.com/git/git/commit/8aa38563b22c84b06ea1fff9638cc1f44fda726f

 0
Author: Dmitry Oksenchuk,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-01-18 17:28:08