From edb46a009e29d8e35884a05e9b827109a2577773 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Tue, 30 Jun 2015 01:55:03 +0300 Subject: [PATCH] Explain there is one thing that cannot be undone Overwritten uncommitted changes. --- pep-git.txt | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) 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? -- 2.39.5