¿Puedes obtener acceso a los archivos almacenados en git si git stash pop se niega a fusionarse?

Resuelto teknopaul asked hace 7 meses • 0 respuestas

¿Cómo obtengo acceso a los datos que git stash se niega a fusionar?

yo corrí

git stash      # two files not stashed since they were not in git yet
git stash -u   # add the sfiles to the stash
git pull
git stash pop

Git se niega a deshacer el almacenamiento porque la extracción tiene dos archivos que se agregaron con (-u archivos sin seguimiento)

error: could not restore untracked files from stash 
The stash entry is kept in case you need it again. 

git stash show 0

no muestra nada. ¿Hay alguna manera de acceder a los archivos que el alijo no aparece? ¿Hay un archivo de parche en .git en alguna parte?

teknopaul avatar Feb 16 '24 18:02 teknopaul
Aceptado

Un alijo es solo una confirmación, por lo que puedes usar herramientas habituales, como git showacceder a los archivos del alijo. Digamos que tengo un cambio no preparado y un archivo sin seguimiento:

$ git status
On branch main
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   README.md

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        example.txt

Si ejecuto git stash -u, termino con un objeto de confirmación llamado refs/stash:

$ git for-each-ref
54884038278578c80ed2aae843c74a38aafcebb7 commit refs/heads/main
879c8e21be397501fd4d9fd1440bff8fa79cc431 commit refs/stash

Los cambios no preparados (es decir, los cambios en los archivos rastreados por git) se almacenan directamente en refs/stash:

$ git show refs/stash
commit 879c8e21be397501fd4d9fd1440bff8fa79cc431
Merge: 5488403 cb7969c b3c4ebe
Author: Alice Example <[email protected]>
Date:   Fri Feb 16 07:05:04 2024 -0500

    WIP on main: 5488403 Initial commit

diff --cc README.md
index b4f9938,b4f9938,0000000..b75fee6
mode 100644,100644,000000..100644
--- a/README.md
+++ b/README.md
@@@@ -1,1 -1,1 -1,0 +1,2 @@@@
  +This is an example of working with `git stash`.
+++This is an unstaged change

Puedo extraer un archivo individual como este:

$ git show refs/stash:README.md
This is an example of working with `git stash`.
This is an unstaged change

Los archivos sin seguimiento se almacenan en refs/stash^3:

$ git show refs/stash^3
commit b3c4ebed5f3566f37697c9adad2f15159a25c731
Author: Alice Example <[email protected]>
Date:   Fri Feb 16 07:05:04 2024 -0500

    untracked files on main: 5488403 Initial commit

diff --git a/example.txt b/example.txt
new file mode 100644
index 0000000..79d897a
--- /dev/null
+++ b/example.txt
@@ -0,0 +1 @@
+This is an untracked file

Y puedo extraer archivos de manera similar:

$ git show refs/stash^3:example.txt
This is an untracked file

También podemos consultar el alijo como una nueva rama. Usar git worktreenos permite poner esto en un nuevo directorio. Lo siguiente crea una nueva rama nombrada unstaged-changescon el contenido de refs/stash^3y la registra en el ../unstaged-changesdirectorio:

$ git worktree add -b unstaged-changes ../unstaged-changes refs/stash^3
Preparing worktree (new branch 'unstaged-changes')
HEAD is now at b3c4ebe untracked files on main: 5488403 Initial commit
$ ls ../unstaged-changes/
example.txt
larsks avatar Feb 16 '2024 12:02 larsks