⇤ ← Revision 1 as of 2008-02-11 22:44:10
Size: 91
Comment: stub
|
Size: 7639
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 2: | Line 2: |
== Tutorial - merging conflicting changes == |
|
Line 5: | Line 7: |
##We learned how to deal with simple [:Merge:merges] in TutorialMerge. Nós aprendemos como lidar com [:Merge:recombinações] simples em ../BrazilianPortugueseTutorialMerge. ##Mercurial handles more complex merge cases, too. It is not all that uncommon for two people to edit the exact same lines of a file, and then have to figure out what to do. These cases are called [:Conflict:conflicts]; figuring out what to do about a conflict is called [:Resolve:resolving] it. O Mercurial também gerencia casos mais complexos de recombinação. Não é tão incomum que duas pessoas editem exatamente as mesmas linhas de um arquivo, e então precisam descobrir o que fazer. Esses casos são chamados [:Conflict:conflitos]; determinar o que fazer em um conflito é chamado [:Resolve:resolvê-lo] . ##Let's first create an artificial conflict situation. As we did previously, let's start by making a [:Clone:clone] of {{{my-hello}}}: Vamos primeiro criar uma situação de conflito artificial. Como fizemos antes, começaremos criando um [:Clone:clone] de {{{my-hello}}}: {{{ $ cd .. $ hg clone my-hello my-hello-not-cvs }}} ##Now let's add a new line of output to {{{hello.c}}}: Agora vamos colocar uma nova linha de saída em {{{hello.c}}}: {{{ $ cd my-hello-not-cvs $ vi hello.c }}} ##We change {{{main}}} to read like this: Nós alteramos {{{main}}} da seguinte forma: {{{#!cplusplus numbers=off int main(int argc, char **argv) { printf("hello, world!\n"); printf("sure am glad I'm not using CVS!\n"); return 0; } }}} ##And we [:Commit:commit] the change: E nós fazemos o [:Commit:commit] da mudança: {{{ $ hg commit -m "Give thanks for dodging bullet" }}} ##Recall that in TutorialFirstChange, we created a [:ChangeSet:changeset] in {{{my-hello-new-output}}} that ''also'' added a second line of output. What happens when we try to [:Pull:pull] that change in here? Lembre-se que, em ../BrazilianPortugueseTutorialFirstChange, nós criamos um [:ChangeSet:changeset] em {{{my-hello-new-output}}} que ''também'' adicionou uma segunda linha de saída. O que acontece quando tentamos fazer um [:Pull:pull] daquela mudança aqui? {{{ $ hg pull ../my-hello-new-output pulling from ../my-hello-new-output searching for changes adding changesets adding manifests adding file changes added 1 changesets with 1 changes to 1 files (+1 heads) (run 'hg heads' to see heads, 'hg merge' to merge) }}} ##So far, so good. Let's try an [:Update:update]. Até aqui tudo bem. Vamos tentar um [:Update:update]. {{{ $ hg update abort: update spans branches, use 'hg merge' or 'hg update -C' to lose changes }}} ##(see also [:Branch]) (veja também [:Branch]) ##As in TutorialMerge, we have to run {{{hg merge}}}. As before, the [:MergeProgram:merge program] will be started under cover. It will usually not be able to merge automatically, because the same line of the same source file has been modified in a different way by each changeset (the one we just [:Commit:commited], and the one we just pulled). Como em ../BrazilianPortugueseTutorialMerge, nós devemos executar {{{hg merge}}}. Como antes, o [:MergeProgram:programa de recombinação] será iniciado automaticamente. Ele tipicamente não será capaz de fazer a recombinação automaticamente, porque a mesma linha do mesmo arquivo fonte foi modificada de modo diferente por cada changeset (o que acabamos de fazer o [:Commit:commit], e o que acabamos de fazer o pull). {{{ $ hg merge }}} ##At this point, what happens depends on what programs are installed on our computer. If we are provident or lucky, and have a graphical merge program installed, we will be able to see what conflicts there are between the two changes, and decide how to resolve them. Neste momento, o que acontece depende de quais programas estão instalados em seu computador. Se somos precavidos (ou se temos sorte), e temos instalado um programa gráfico de recombinação, nós seremos capazes de ver quais conflitos existem entre os dois changesets, e decidir como resolvê-los. ##Below is the sample conflicts shown in vim editor on a Linux system. Abaixo estão os conflitos do exemplo exibidos no editor vim em um sistema Linux. {{{ /* * hello.c * * Placed in the public domain by Bryan O'Sullivan * * This program is not covered by patents in the United States or other * countries. */ #include <stdio.h> int main(int argc, char **argv) { printf("hello, world!\n"); <<<<<<< /home/motoko/project/my-hello-not-cvs/hello.c.orig.197516148 printf("sure am glad I'm not using CVS!\n"); ||||||| /tmp/hello.c~base.aYR8Pf ======= printf("sure am glad I'm using Mercurial!\n"); >>>>>>> /tmp/hello.c~other.F7OpXy return 0; } }}} ##Mercurial is using a per-file 3-way merge. This means that there are 3 input files for merging process, and those are: ## * Local file (from current repository) ## * Other file (from repository being merged) ## * Base file (last version of file before branches separated) Mercurial está usando uma recombinação de três vias por arquivo. Isso quer dizer que há 3 arquivos de entrada para o processo de recombinação, que são: * o arquivo local (do repositório atual) * o outro arquivo (do repositório sendo recombinado) * o arquivo base (a versão mais recente do arquivo antes da divergência) ##For more information about 3-way, see [http://revctrl.org/ThreeWayMerge ThreeWayMerge] on the [http://revctrl.org/ Revctrl wiki]. Para mais informações a respeito da recombinação de 3 vias, veja [http://revctrl.org/ThreeWayMerge ThreeWayMerge] no wiki [http://revctrl.org/ Revctrl] . ##Else, if we do not have a graphical merge program installed, we will be dropped into a text editor, which will be visiting the file we need to merge. Doing this by hand is '''highly''' error-prone and tedious. It is best to exit the editor and use the {{{hg rollback}}} command to reverse the effect of the pull, then install a merge program, and then try again. Caso não tenhamos instalado um programa gráfico de recombinação, será executado um editor de texto, que irá abrir os arquivos conflitantes um a um. Fazer isso à mão é '''altamente''' entediante e falível. É melhor sair do editor e usar o comando {{{hg rollback}}} para reverter os efeitos da recombinação, instalar um programa de recombinação, e tentar novamente. ##(~-Note: before Mercurial version 0.9, `hg update -m` should have been used in place of `hg merge` and `hg undo` should have been used instead of `hg rollback`-~). (~-Nota: em versões anteriores ao Mercurial 0.9, `hg update -m` deve ser usado ao invés de `hg merge` e `hg undo` deve ser usado ao invés de `hg rollback`-~). ##(~-Note: what do we do with the remaining unnecessary additional file hello.c.orig?-~). ##As before, be sure to commit this change to the repository once the merge is complete: Como anteriormente, esteja certo de fazer o commit dessa alteração para o repositório, uma vez que a recombinação esteja concluída: {{{ $ hg commit -m "Merged changes from my-hello-new-output" }}} ##There shouldn't be any output from this command. Este comando não deve gerar uma saída. ##Now let's continue and finish on to TutorialConclusion. Agora continuaremos e concluiremos em ../BrazilianPortugueseTutorialConclusion. ##See also: ImergeExtension |
Tutorial - merging conflicting changes
(This page in English: [:TutorialConflict])
Nós aprendemos como lidar com [:Merge:recombinações] simples em ../BrazilianPortugueseTutorialMerge.
O Mercurial também gerencia casos mais complexos de recombinação. Não é tão incomum que duas pessoas editem exatamente as mesmas linhas de um arquivo, e então precisam descobrir o que fazer. Esses casos são chamados [:Conflict:conflitos]; determinar o que fazer em um conflito é chamado [:Resolve:resolvê-lo] .
Vamos primeiro criar uma situação de conflito artificial. Como fizemos antes, começaremos criando um [:Clone:clone] de my-hello:
$ cd .. $ hg clone my-hello my-hello-not-cvs
Agora vamos colocar uma nova linha de saída em hello.c:
$ cd my-hello-not-cvs $ vi hello.c
Nós alteramos main da seguinte forma:
int main(int argc, char **argv)
{
printf("hello, world!\n");
printf("sure am glad I'm not using CVS!\n");
return 0;
}
E nós fazemos o [:Commit:commit] da mudança:
$ hg commit -m "Give thanks for dodging bullet"
Lembre-se que, em ../BrazilianPortugueseTutorialFirstChange, nós criamos um [:ChangeSet:changeset] em my-hello-new-output que também adicionou uma segunda linha de saída. O que acontece quando tentamos fazer um [:Pull:pull] daquela mudança aqui?
$ hg pull ../my-hello-new-output pulling from ../my-hello-new-output searching for changes adding changesets adding manifests adding file changes added 1 changesets with 1 changes to 1 files (+1 heads) (run 'hg heads' to see heads, 'hg merge' to merge)
Até aqui tudo bem. Vamos tentar um [:Update:update].
$ hg update abort: update spans branches, use 'hg merge' or 'hg update -C' to lose changes
(veja também [:Branch])
Como em ../BrazilianPortugueseTutorialMerge, nós devemos executar hg merge. Como antes, o [:MergeProgram:programa de recombinação] será iniciado automaticamente. Ele tipicamente não será capaz de fazer a recombinação automaticamente, porque a mesma linha do mesmo arquivo fonte foi modificada de modo diferente por cada changeset (o que acabamos de fazer o [:Commit:commit], e o que acabamos de fazer o pull).
$ hg merge
Neste momento, o que acontece depende de quais programas estão instalados em seu computador. Se somos precavidos (ou se temos sorte), e temos instalado um programa gráfico de recombinação, nós seremos capazes de ver quais conflitos existem entre os dois changesets, e decidir como resolvê-los.
Abaixo estão os conflitos do exemplo exibidos no editor vim em um sistema Linux.
/* * hello.c * * Placed in the public domain by Bryan O'Sullivan * * This program is not covered by patents in the United States or other * countries. */ #include <stdio.h> int main(int argc, char **argv) { printf("hello, world!\n"); <<<<<<< /home/motoko/project/my-hello-not-cvs/hello.c.orig.197516148 printf("sure am glad I'm not using CVS!\n"); ||||||| /tmp/hello.c~base.aYR8Pf ======= printf("sure am glad I'm using Mercurial!\n"); >>>>>>> /tmp/hello.c~other.F7OpXy return 0; }
Mercurial está usando uma recombinação de três vias por arquivo. Isso quer dizer que há 3 arquivos de entrada para o processo de recombinação, que são:
- o arquivo local (do repositório atual)
- o outro arquivo (do repositório sendo recombinado)
- o arquivo base (a versão mais recente do arquivo antes da divergência)
Para mais informações a respeito da recombinação de 3 vias, veja [http://revctrl.org/ThreeWayMerge ThreeWayMerge] no wiki [http://revctrl.org/ Revctrl] .
Caso não tenhamos instalado um programa gráfico de recombinação, será executado um editor de texto, que irá abrir os arquivos conflitantes um a um. Fazer isso à mão é altamente entediante e falível. É melhor sair do editor e usar o comando hg rollback para reverter os efeitos da recombinação, instalar um programa de recombinação, e tentar novamente.
(Nota: em versões anteriores ao Mercurial 0.9, hg update -m deve ser usado ao invés de hg merge e hg undo deve ser usado ao invés de hg rollback).
Como anteriormente, esteja certo de fazer o commit dessa alteração para o repositório, uma vez que a recombinação esteja concluída:
$ hg commit -m "Merged changes from my-hello-new-output"
Este comando não deve gerar uma saída.
Agora continuaremos e concluiremos em ../BrazilianPortugueseTutorialConclusion.