Solucionado (ver solução)
Solucionado
(ver solução)
3
respostas

erro com checkout para master

Boa noite! Quando eu tento retornar para a master, ocorre o seguinte erro:

error: Your local changes to the following files would be overwritten by checkout:
        arquivo1.txt

podem me ajudar? Obrigada!!

Edit1: tentei fazre um commit, mas acho que piorou as coisas Segue mais um erro:

$ git merge titulo
Auto-merging arquivo1.txt
CONFLICT (content): Merge conflict in arquivo1.txt
Automatic merge failed; fix conflicts and then commit the result.

os comandos que eu dei foram:

alees@Alexandra MINGW64 ~/OneDrive/Documentos/git-e-github/alexandra (titulo)
$ git checkout master
error: Your local changes to the following files would be overwritten by checkout:
        arquivo1.txt
Please commit your changes or stash them before you switch branches.
Aborting

alees@Alexandra MINGW64 ~/OneDrive/Documentos/git-e-github/alexandra (titulo)
$ git branch
  master
* titulo

alees@Alexandra MINGW64 ~/OneDrive/Documentos/git-e-github/alexandra (titulo)
$ git checkout master
error: Your local changes to the following files would be overwritten by checkout:
        arquivo1.txt
Please commit your changes or stash them before you switch branches.
Aborting

alees@Alexandra MINGW64 ~/OneDrive/Documentos/git-e-github/alexandra (titulo)
$ ^C

alees@Alexandra MINGW64 ~/OneDrive/Documentos/git-e-github/alexandra (titulo)
$ git checkout -b titulo
fatal: A branch named 'titulo' already exists.

alees@Alexandra MINGW64 ~/OneDrive/Documentos/git-e-github/alexandra (titulo)
$ commit -m "Editando título"
bash: commit: command not found

alees@Alexandra MINGW64 ~/OneDrive/Documentos/git-e-github/alexandra (titulo)
$ commit -m "Editando título"
bash: commit: command not found

alees@Alexandra MINGW64 ~/OneDrive/Documentos/git-e-github/alexandra (titulo)
$ git commit -m "Editando título"
On branch titulo
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:   arquivo1.txt

no changes added to commit (use "git add" and/or "git commit -a")

alees@Alexandra MINGW64 ~/OneDrive/Documentos/git-e-github/alexandra (titulo)
$ git commit -m "Adicionando lista no título"
On branch titulo
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:   arquivo1.txt

no changes added to commit (use "git add" and/or "git commit -a")

alees@Alexandra MINGW64 ~/OneDrive/Documentos/git-e-github/alexandra (titulo)
$ git checkout master
error: Your local changes to the following files would be overwritten by checkout:
        arquivo1.txt
Please commit your changes or stash them before you switch branches.
Aborting

alees@Alexandra MINGW64 ~/OneDrive/Documentos/git-e-github/alexandra (titulo)
$ git add .

alees@Alexandra MINGW64 ~/OneDrive/Documentos/git-e-github/alexandra (titulo)
$ git commit -m "arrumando bug"
[titulo a2452fd] arrumando bug
 1 file changed, 2 insertions(+), 1 deletion(-)

alees@Alexandra MINGW64 ~/OneDrive/Documentos/git-e-github/alexandra (titulo)
$ git status
On branch titulo
nothing to commit, working tree clean

alees@Alexandra MINGW64 ~/OneDrive/Documentos/git-e-github/alexandra (titulo)
$ git checkout master
Switched to branch 'master'

alees@Alexandra MINGW64 ~/OneDrive/Documentos/git-e-github/alexandra (master)
$ git commit -m "Corrigindo bug2"
On branch master
nothing to commit, working tree clean

alees@Alexandra MINGW64 ~/OneDrive/Documentos/git-e-github/alexandra (master)
$ git status
On branch master
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:   arquivo1.txt

no changes added to commit (use "git add" and/or "git commit -a")

alees@Alexandra MINGW64 ~/OneDrive/Documentos/git-e-github/alexandra (master)
$ git add .

alees@Alexandra MINGW64 ~/OneDrive/Documentos/git-e-github/alexandra (master)
$ git commit -m "Corrigindo bug again"
[master 534320a] Corrigindo bug again
 1 file changed, 3 insertions(+), 1 deletion(-)

meus arquivos que eu estou usando para a aula são em txt... vou deixar aqui tb como ficou dentro do arquivo:

arquivo editado pela ana

<<<<<<< HEAD
teste bug
=======
-alterando o titulo-
-corrigindo bug-
>>>>>>> titulo
3 respostas

Olá Alexandra, tudo bem? O erro apresentado informa que você fez algumas mudanças no "arquivo1.txt" no seu branch "titulo" e o Git informa isso no erro

Your local changes to the following files would be overwritten by checkout:
        arquivo1.txt

E nesse caso as alterações seriam substituídas ao trocar para o branch "master", ele também indica as possíveis soluções, que são:

Please commit your changes or stash them before you switch branches.

No caso, você deve commit as mudanças no branch "titulo" antas de mudar de branch ou então descartas as mudanças e voltar o arquivo ao estado inicial, que provavelmente é igual ao "arquivo.txt" da branch "master".

Agora como já aconteceu o conflito nesse arquivo:

arquivo editado pela ana

<<<<<<< HEAD
teste bug
=======
-alterando o titulo-
-corrigindo bug-
>>>>>>> titulo

Você tem que escolher qual é a parte que você deseja manter, no caso excluindo o que não quiser e depois executar um novo commit, nesse cenário você tem que editar o arquivo e deixá-lo da seguinte forma:

arquivo editado pela ana

-alterando o titulo-
-corrigindo bug-

E depois executar novamente o outro commit, note que excluir as linhas:

<<<<<<< HEAD
teste bug
=======
>>>>>>> titulo

Onde somente a linha com o texto "teste bug" estava realmente presente em um dos seus arquivos (ou do branch "master" ou do branch "titulo") e as demais linhas foram colocadas pelo próprio Git pra indicar o conflito!

Espero ter ajudado!

Bom dia Jonilson!! Ajudou bastente sim, muito obrigada!!

Outra dúvida que eu tenho é, por qual motivo não abre o VIM quando eu fiz o merge, não abriu esse editor... =/

solução!

Alexandra, se não estou enganado o VIM só abre quando temos mais de um commit para fazer o merge, é onde podemos informar uma mensagem só para todos os commits que fazer incluir na outra branch!

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software