From a61e675b9b21c180d2e0dace9ac3b7cd44662b30 Mon Sep 17 00:00:00 2001 From: Ben Lynn Date: Tue, 5 Aug 2008 20:28:36 -0700 Subject: [PATCH] Safeguards, and how to override them. --- clone.txt | 2 +- grandmaster.txt | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/clone.txt b/clone.txt index 50a5219..1a94e88 100644 --- a/clone.txt +++ b/clone.txt @@ -27,7 +27,7 @@ to push the current state to the other computer. Next time you're logged in to t $ git checkout HEAD . -to update the files before working on them. Be aware that you'll lose any uncommitted changes when you do this. Because more care is required, I prefer sticking to pulls for this use case. +to update the files before working on them, though this won't work if you have uncommitted changes. Because more work is required, I prefer sticking to pulls for this use case. === Classic Source Control === diff --git a/grandmaster.txt b/grandmaster.txt index 2aa644c..b15ca87 100644 --- a/grandmaster.txt +++ b/grandmaster.txt @@ -211,3 +211,27 @@ the "refs/heads/" and ignore errors: $ git symbolic-ref HEAD 2> /dev/null | cut -b 12- See http://git.or.cz/[the Git homepage] for more examples. + +=== Daring Stunts === + +Recent versions of Git make it difficult for the user to accidentally destroy data. This is perhaps the most compelling reason to upgrade. + +Nonetheless, what if you truly want to destroy data? We'll show how to override the safeguards for common commands. Only use them if you know what you are doing. + +*Checkout*: If you have uncommitted changes, checkout will fail. To destroy your changes, and checkout a given commit anyway, use the force flag: + + $ git checkout -f COMMIT + +*Reset*: Reset also fails in the presence of uncommitted changes. To force it through, run: + + $ git reset --hard [COMMIT] + +*Branch*: Deleting branches fails if this causes changes to be lost. To force a deletion, type: + + $ git branch -D BRANCH # instead of -d + +Similarly, attempting to overwrite a branch via a move fails if this causes data loss. To force a branch move through, type: + + $ git branch -M [SOURCE] TARGET # instead of -m + +Unlike checkout and reset, no data is lost yet. The changes are still stored in the .git subdirectory, and can be retrieved by recovering the appropriate hash from `.git/logs` (see "HEAD-hunting" above). The data is deleted the next time garbage is collected. -- 2.11.4.GIT