I was working on a branch called task-1. Unintentionally, I changed the branch and made several modifications to the branch called task-2. How do I reverse the changes in branch task-2 without having to commit and delete everything that was done?
I was working on a branch called task-1. Unintentionally, I changed the branch and made several modifications to the branch called task-2. How do I reverse the changes in branch task-2 without having to commit and delete everything that was done?
If you:
task-2
and kept changing these (and other) files thinking you were in task-1
task-1
and remove them from task-2
You have the following options:
Simply go back to task-1
.
git checkout task-1
git will load all changes from task-2
to task-1
. When you commit everything in task-1
and return to task-2
, you will see that the task-2
branch is intact
Still in task-2, use the command:
git stash -u # o -u inclui os arquivos que criou, também
Go to branch task-1
and apply the command to download the changes:
git checkout task-1
git stash pop
In branch task-2
you can create a file with all changes:
git diff HEAD >> arquivo_todas_alteracoes.diff
Clear branch modifications:
git reset HEAD . # mover todas alterações do stage
git clean -f -d # limpar todas as alterações
Go to branch task-1
and apply changes to diff file:
git checkout task-1
git apply arquivo_todas_alteracoes.diff