X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=pep-git.txt;h=15ca892eb375934a28d722172c334dcf889f398e;hb=21c8d5852964d132f0608364b7e0546c7657338d;hp=d42184b4fbda81f396ef57356f5bb91e2caa3c2f;hpb=e58b976218dba56b2eaa767d09d4ddb41186d0f8;p=git-wiki.git diff --git a/pep-git.txt b/pep-git.txt index d42184b..15ca892 100644 --- a/pep-git.txt +++ b/pep-git.txt @@ -496,7 +496,25 @@ 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 preserving them. + +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 new commits +over non-committed files. + +But there are commands that do exactly that - overwrite files in the +working tree. Commands like ``git checkout $PATHs`` or ``git reset +--hard`` silently overwrite 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, remove. But save your changes in git database, +either commit changes or at least stash them with ``git stash``. Merge or rebase?