2017-09-26 4 views
0

J'ai fait un PR sur GitHub (Enterprise) avec peu de commits. Mes critiques ont identifié une petite erreur sur un commettras:Quelle solution pour modifier une demande de tirage?

* a401341c Did this (HEAD -> foo) 
* 08e97f86 Did that 
* 616cd4ad Done that 
* f3c6151b Accomplished this 
* 1af6e74f Fix this <-- Error there 
* a099fc19 Finished this 
* ab726eb3 Cherry-picked this (master, origin/master) 

La première solution est de revenir tous les commits après 1af6e74f parce que je ne peux pas revenir dessus sans conflits, puis appliquez de nouveau tous les commits avec la correction:

* 0c99cf29 Reapply Did this (HEAD -> foo) 
* 8806f36b Reapply Did that 
* 572e1122 Reapply Done that 
* 64ea3dc8 Reapply Accomplished this 
* 81e20976 Fix this (this time correctly) 
* d78a4534 Revert Fix this <-- Error there 
* c0d817a9 Revert Accomplished this 
* ed2bb3b2 Revert Done that 
* ea34322a Revert Did that 
* f81b78a3 Revert Did this 
* a401341c Did this 
* 08e97f86 Did that 
* 616cd4ad Done that 
* f3c6151b Accomplished this 
* 1af6e74f Fix this <-- Error there 
* a099fc19 Finished this 
* ab726eb3 Cherry-picked this (master, origin/master) 

Puis git push pour mettre à jour mon PR.

La deuxième solution consisterait à adopter un git push -f

git checkout 1af6e74f 
git commit --amend -am "Fix this (with corrections)" 
git rebase --onto a401341c f3c6151b HEAD # Not sure this will work as written 
git branch -f foo HEAD 
git push -f 

est l'ancienne solution, une bonne solution et celle-ci toujours une mauvaise?

+1

Je ne voudrais pas utiliser non plus, je voudrais juste fixer le bobo dans un nouveau commit. Bien sûr, l'histoire serait plus propre si vous rebasiez la branche. Mais le rebasement ne serait conseillé que si votre branche n'était partagée par personne d'autre. Donc la réponse à votre question est que cette dernière solution est bonne si la branche n'est pas partagée. –

+0

Eh bien, je ne peux pas ... Ce n'était pas clair dans ma question difficile parce que j'ai utilisé 'git am mypatch' où je ne peux pas simplement appliquer un patch. J'ai besoin de revenir et de modifier un commit spécifique. C'est comme si je fais 's/a \ w/b/g' sur un commit, je ne peux pas vraiment faire' s/b/a/g' par la suite. – nowox

+0

Si vous ne pouvez pas rebaser, alors pourquoi avez-vous demandé à ce sujet, ou cette question était-elle juste hypothétique? –

Répondre

1

Question:

Quelle est la diff entre votre ancienne branche et la nouvelle branche (git diff a401341c 0c99cf29)?
Est-ce que cela ressemble à un patch raisonnable, ce qui indique clairement comment le bug a été corrigé?


Si elle le fait, il suffit de prendre le nouveau contenu et engager cela comme un commit sur le dessus de votre ancienne branche:

git checkout foo 

# just to be on the safe side : work on a new temporary branch 
git checkout -b wip 

# go back to the old sate : 
git reset --hard a401341c # <- original "Did this" commit 

# get the content from new branch : 
git checkout 0c99cf29 . # <- don't forget the "." 

# check that it matches what you expect : 
git diff [--cached] ... 
git difftool -d [--cached] ... 

# if OK : commit ! 
git commit 


# make your local "foo" branch point to this commit : 
git checkout foo 
git reset --hard wip 
git branch -d wip 

# push : 
git push origin foo 
+0

Dans ce cas, je dois faire 'git push -f origine foo' qui n'est normalement pas autorisé. Droite ? – nowox

+0

Ce sera un push regumar, pas un 'git push -f'. Vos modifications seront validées en haut de la branche distante. – LeGEC