02 - Essencial do Git - Parte IV
- #GitHub
- #Git
Desfazendo coisas
Excluindo alterações antes do stage
$ echo "Nova linha adicionada 7" >> Readme.md
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: Readme.md
no changes added to commit (use "git add" and/or "git commit -a")
$ git diff
diff --git a/Readme.md b/Readme.md
index 654e88c..fba9807 100644
--- a/Readme.md
+++ b/Readme.md
@@ -7,3 +7,4 @@ Nova linha adicionada 3
Nova linha adicionada 4
Nova linha adicionada 5
Nova linha adicionada 6
+Nova linha adicionada 7
Alteração adicionada.
$ git checkout Readme.md
$ git status
On branch master
nothing to commit, working tree clean
$ git diff
$
Excluindo alterações no stage
$ echo "Nova linha adicionada 7" >> Readme.md
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: Readme.md
no changes added to commit (use "git add" and/or "git commit -a")
$ git add .
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: Readme.md
Neste ponto, as modificações já foram enviadas para o stage.
$ git reset HEAD
Unstaged changes after reset:
M Readme.md
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: Readme.md
no changes added to commit (use "git add" and/or "git commit -a")
Modificações removidas do stage.
$ git checkout Readme.md
$ git status
On branch master
nothing to commit, working tree clean
$
Modificações removidas do arquivo.
Excluindo alterações no commit
- soft: remove alterações do commit, deixando no stage.
$ git reset --soft 9936c23
- mixed: remove alterações do commit e stage, deixando no arquivo.
$ git reset --mixed 9936c23
- hard: remove todas as alterações.
$ git reset --hard 9936c23
Importante:
- Sempre informar o hash do commit anterior ao que será excluído!
- Utilize o reset hard antes do push.
Até +.