2016-02-23 16 views
5

Ho fatto un semplice esempio per scrivere alcune funzioni GIT. Solo un file di testo nel repository:Git Revert "non è possibile eseguire il ripristino perché si hanno file non raggruppati"

1 

aggiunto e commesso il cambiamento

poi cambiato il txt. file per:

1 
2 

aggiunto e commesso il cambiamento

registro Git dà il seguente risultato:

commit 00e59212a6... 
.. 
second commit 

commit 7c319d587.... 
.. 
first commit 

a quel punto ho voglia di tornare al primo commit (ma non voglio . utilizzare "reset --hard" ho provato:

git revert 7c319d587 

ma ho ottenuto il seguente messaggio di errore:

revert is not possible because you have unmerged files 
hint: Fix them up in the work tree, and the use "git add/rm 
hint: as appropriate to mark resolution and make a commit 

Sono nuovo di GIT - prima che ho usato SVN, lì si può gestire queste cose molto semplici così mi chiedo se questo semplice le cose devono pochi passi in GIT?

Grazie mille per il vostro aiuto.

+2

Sembra che qualcos'altro abbia aggiunto un file (ad esempio file di backup dell'editor). Prova 'git status' per avere una visione di ciò che pensa git sta succedendo. – slothbear

+0

stato git -> sul master del ramo; al momento stai ripristinando commit 7c319d587. (Risolvi i conflitti ed esegui "git revert --continue") (usa git revert --abort per annullare l'operazione di ripristino); percorsi non raggruppati: (usa "git reset Heat .." per non rilasciare); cancellato da loro: test.txt; nessuna modifica aggiunta al commit (usa "git add" eo "git commit -a) –

risposta

2

Beh, ho provato quello che pensate di fatto, facendo esattamente quello che hai scritto

cd /tmp 
mkdir so35588521 
cd so35588521 
git init 
# Initialized empty Git repository in /tmp/so35588521/.git/ 
touch 1 
echo "1" > 1 
git add . 
git commit -m "first" 
# [master (root-commit) 173f431] first 
# 1 file changed, 0 insertions(+), 0 deletions(-) 
# create mode 100644 1 
touch 2 
touch 3 
git add . 
git commit -m "second" 
# [master a9fdcc9] second 
# 2 files changed, 0 insertions(+), 0 deletions(-) 
# create mode 100644 2 
# create mode 100644 3 
git log 
# commit a9fdcc9338c9b3de25c211580a35ab63d1d57c2e 
# Author: Me and my email 
# Date: Tue Feb 23 22:46:50 2016 +0100 
git revert a9fd 
# [master dd5a86e] Revert "second" 
# 2 files changed, 0 insertions(+), 0 deletions(-) 
# delete mode 100644 2 
# delete mode 100644 3 

Come si può vedere - tutto è andato bene. Così, ho pensato, AHA! Deve aver fatto qualcos'altro, e ha dimenticato di menzionarlo su SO. Oh bene, capirò cosa ha fatto usando la mia sfera di cristallo comunque. Qual è il senso di ciò che gira intorno inutile.

Quindi, unire, ha detto git. Quindi, facciamo un ramo e proviamo a unirlo con il nostro ramo principale.

git checkout -b a_branch 
# Switched to a new branch 'a_branch' 
echo "2" > 1 
git status 
# On branch a_branch ... 
git add . 
git commit -m "third" 
# [a_branch 96d3a7a] third 
# 1 file changed, 1 insertion(+), 1 deletion(-) 
git checkout master 
# Switched to branch 'master' 
echo "3" > 1 
git add . 
git commit -m "fourth" 
# [master 7f72eec] fourth 
# 1 file changed, 2 insertions(+), 1 deletion(-) 
#### Now we have first commit, and second, and revert second, and two commits: third on **a_branch** branch and fourth on **master**. 
git merge a_branch 
# Auto-merging 1 
# CONFLICT (content): Merge conflict in 1 
# Automatic merge failed; fix conflicts and then commit the result. 
# *Oh DANG* whyy? Git stop, don't do that it hurts, revert! 
git revert last_commit_id_from_git_log 
# error: revert is not possible because you have unmerged files. 
# hint: Fix them up in the work tree, and then use 'git add/rm <file>' 
# hint: as appropriate to mark resolution and make a commit. 
# fatal: revert failed 
# *Git nope!* 

Ora, che è stato solo io indovinare, e portando un po 'di umorismo per SO, spero. Se questo NON è ciò che hai fatto, potresti dirci per favore i passi esatti che hai fatto? Dal momento che non riesco a replicare l'errore che stai avendo, e quindi mi sento insoddisfatto di non essere in grado di farlo.

EDIT:

Da OP insiste sul fatto che sicuramente non ha fatto un ramo ...

rm * 
rm -rf .git 
git init 
echo -e "line one\n" > 1 
git add . 
git ci -m "first" 
echo -e "line two\n" >> 1 
git ci -a -m "second" 
git log 
# commit 23d710610d98c1046844870557208f335e76a933 
# Author: ME <[email protected]> 
# Date: Tue Feb 23 23:31:28 2016 +0100 
# 
#  second 
# 
# commit 22873fb5fbf06d80a1779fe6740060c660d68714 
# Author: ME <[email protected]> 
# Date: Tue Feb 23 23:30:47 2016 +0100 
# 
# first 

git revert "first" 
# fatal: bad revision 'first' # but OK i assume You used id, so, 
git revert 22873fb5fbf06d80 
# error: could not revert 22873fb... first 
# hint: after resolving the conflicts, mark the corrected paths 
# hint: with 'git add <paths>' or 'git rm <paths>' 
# hint: and commit the result with 'git commit' 

Ahaaa, ora ho capito! E quello ... è bizzaare.

Ok, ho controllato ed effettivamente hai ragione, sul mio git --version 2.6.3 ho potuto replicare questo comportamento. In realtà, penso che sei entrato in un caso piuttosto angusto qui. Quello che è successo è che dopo il tuo secondo commit, git ha memorizzato le modifiche che hai apportato al file test.txt e mantenuto quelle modifiche. Ora gli hai detto (si?) A git revert first_commit_id che ha effettivamente creato il file test.txt. Non posso dirlo con certezza, ma questo mi sembra un piccolo insetto.

Tuttavia! Se, nel secondo commit, aggiungi il file, ad esempio test2.txt (quindi avresti due file con versione nel repository git), quindi revert funziona.

+0

:) grazie: 1) creato un file txt/added/commit 2) aggiunta una seconda riga a quel file/salvato/aggiunto/commited 3) git revert "first commit" -> got error: non è possibile perché hai file non raggruppati 4) Non ho mai cambiato o creato un nuovo branch 5) git status -> su branch master, stai ripristinando il commit 7c319d587. (Risolvi i conflitti ed esegui "git revert --continue") (usa git revert --abort per annullare l'operazione di ripristino); percorsi non raggruppati: (usa "git reset Heat .." per non rilasciare); txt; nessuna modifica aggiunta al commit (usa "git add" eo "git commit -a) –

+0

Lasciami solo aggiungere quello per rispondere, così puoi confermare che hai fatto esattamente questo. Non riesco ancora a replicare ciò che hai fatto. – JustMe

+0

Quindi, dal momento che posso replicarlo, e considerare questo bug minore, emetterò una richiesta di bug per i manutentori di git (dopo aver controllato il git del bordo sanguinante) a meno che tu non voglia :) – JustMe

Problemi correlati