git stash - > combinar el cambio guardado con los cambios actuales


Realicé algunos cambios en mi rama y me di cuenta de que había guardado algunos otros cambios necesarios en dicha rama. Lo que quiero es una forma de combinar mis cambios guardados con los cambios actuales.

¿Hay alguna manera de hacer esto?

Es más por conveniencia, eventualmente me di por vencido y comprometí primero mis cambios actuales, luego mis cambios guardados, pero hubiera preferido hacerlos de un solo golpe.

Author: SQB, 2012-07-26

5 answers

Acabo de descubrir que si sus cambios no confirmados se agregan al índice (es decir, "preparado", utilizando "git add ..."), luego "git stash apply "(y, presumiblemente," git stash pop") hará una combinación adecuada. Si no hay conflictos, eres de oro. Si no, resolverlos como de costumbre con "git mergetool", o manualmente con un editor.

Para ser claros, este es el proceso del que estoy hablando:

mkdir test-repo && cd test-repo && git init
echo test > test.txt
git add test.txt && git commit -m "Initial version"

# here's the interesting part:

# make a local change and stash it:
echo test2 > test.txt
git stash

# make a different local change:
echo test3 > test.txt

# try to apply the previous changes:
git stash apply
# git complains "Cannot apply to a dirty working tree, please stage your changes"

# add "test3" changes to the index, then re-try the stash:
git add test.txt
git stash apply
# git says: "Auto-merging test.txt"
# git says: "CONFLICT (content): Merge conflict in test.txt"

... que es probablemente lo que estás buscando.

 184
Author: Joshua Warner,
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
2013-05-17 16:25:02

Ejecutar git stash pop o git stash apply es esencialmente una fusión. No debería haber necesitado confirmar sus cambios actuales a menos que los archivos cambiados en el alijo también se cambien en la copia de trabajo, en cuyo caso habría visto este mensaje de error:

error: Your local changes to the following files would be overwritten by merge:
       file.txt
Please, commit your changes or stash them before you can merge.
Aborting

En ese caso, no puedes aplicar el alijo a tus cambios actuales en un solo paso. Puedes confirmar los cambios, aplicar el stash, confirmar de nuevo y aplastar esas dos confirmaciones usando git rebase si realmente no quieres dos confirmaciones, pero eso puede ser más problemas que valen la pena.

 66
Author: Brandan,
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
2012-07-26 19:24:56

Lo que quiero es una forma de combinar mis cambios guardados con el actual cambios

Aquí hay otra opción para hacerlo:

git stash show -p|git apply
git stash drop

git stash show -p mostrará el parche del último alijo guardado. git apply lo aplicará. Una vez finalizada la fusión, el alijo fusionado se puede soltar con git stash drop.

 14
Author: ks1322,
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-12-29 15:22:17

Como sugirió @Brandan, esto es lo que necesitaba hacer para moverme

error: Your local changes to the following files would be overwritten by merge:
       file.txt
Please, commit your changes or stash them before you can merge.
Aborting

Siga este proceso:

git status  # local changes to `file`
git stash list  # further changes to `file` we want to merge
git commit -m "WIP" file
git stash pop
git commit -m "WIP2" file
git rebase -i HEAD^^  # I always use interactive rebase -- I'm sure you could do this in a single command with the simplicity of this process -- basically squash HEAD into HEAD^
# mark the second commit to squash into the first using your EDITOR
git reset HEAD^

Y te quedarás con cambios locales completamente fusionados a file, listo para hacer más trabajo/limpieza o hacer un solo commit bueno. O bien, si sabe que el contenido fusionado de file será correcto, puede escribir un mensaje apropiado y omitir git reset HEAD^.

 0
Author: knickum,
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-01-13 16:15:59

Otra opción es hacer otro "git stash" de los cambios locales sin confirmar, luego combinar los dos git stash. Desafortunadamente, git parece no tener una manera de combinar fácilmente dos escondites. Así que una opción es crear dos .diff archivos y aplicarlos a ambos lest a menos que no sea un commit extra y no implique un proceso de diez pasos: /

Cómo hacerlo: https://stackoverflow.com/a/9658688/32453

 -1
Author: rogerdpack,
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 12:03:03