From: Oleg Broytman Date: Mon, 29 Jun 2015 22:55:03 +0000 (+0300) Subject: Explain there is one thing that cannot be undone X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=edb46a009e29d8e35884a05e9b827109a2577773;p=git-wiki.git Explain there is one thing that cannot be undone Overwritten uncommitted changes. --- diff --git a/pep-git.txt b/pep-git.txt index d42184b..9340703 100644 --- a/pep-git.txt +++ b/pep-git.txt @@ -496,7 +496,26 @@ of merge. See the discussion `How to revert a faulty merge One thing that cannot be undone ------------------------------- -"Commit early, commit often". +Whatever you undo, there is one thing that cannot be undone - +overwritten uncommitted changes. Uncommitted changes don't belong to +git so git cannot help with them - no way. + +Most of the time git warns you when you're going to execute a command +that overwrites uncommitted changes. Git warns you when you try to +switch branches with ``git checkout``. It warns you when you're going +to rebase with non-clean working tree. It refuses to pull commits over +non-committed files. + +But there are commands that designed exactly for that - overwriting +files in the working tree. With commands like ``git checkout $PATHs`` +or ``git reset --hard`` git silently overwrites files including your +uncommitted changes. + +With that in mind you can understand the stance "commit early, commit +often". Commit as often as possible. Commit on every save in your +editor or IDE. You can edit your commits before pushing - change, +reorder, combine. But save your changes in git database, either in +commits or at least in stashes. Merge or rebase?