2
I was working on a branch called task-1. I accidentally switched branches and made several modifications to the task-2 branch. How do I reverse the changes in the task-2 branch without committing and deleting everything that was done?
2
I was working on a branch called task-1. I accidentally switched branches and made several modifications to the task-2 branch. How do I reverse the changes in the task-2 branch without committing and deleting everything that was done?
0
If you:
task-2
and kept changing these (and other) files thinking it was in the task-1
task-1
and remove them from task-2
You have the following options:
Just go back to the task-1
.
git checkout task-1
git will load all changes from task-2
to the task-1
. By committing everything in task-1
and go back to task-2
, will see that the branch task-2
will be intact
Still on task-2, use command:
git stash -u # o -u inclui os arquivos que criou, também
Go to the 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 the 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 the branch task-1
and apply the diff file changes:
git checkout task-1
git apply arquivo_todas_alteracoes.diff
Browser other questions tagged git
You are not signed in. Login or sign up in order to post.
Where are these changes? You’ve committed or are on staging area?
– Woss
I didn’t commit. You’re not staging.
– João Filipe
So just switch to the right branch.
– Jéf Bueno
Can perform
git stash
, effect the checkout to the correct branch and apply withgit stash apply
.– Woss
Or else
git stash pop
, that cleans thestash
– Jefferson Quesado