Download "user manual"
Transcript
Chapter 7. Git Grandmastery The new directory and the files within can be thought of as a clone, except since the history is shared, the two trees automatically stay in sync. There’s no need to merge, push, or pull. 7.8. Daring Stunts These days, Git makes it difficult for the user to accidentally destroy data. But if you know what you are doing, you can override safeguards for common commands. Checkout: Uncommitted changes cause checkout to fail. To destroy your changes, and checkout a given commit anyway, use the force flag: $ git checkout -f HEAD^ On the other hand, if you specify particular paths for checkout, then there are no safety checks. The supplied paths are quietly overwritten. Take care if you use checkout in this manner. Reset: Reset also fails in the presence of uncommitted changes. To force it through, run: $ git reset --hard 1b6d Branch: Deleting branches fails if this causes changes to be lost. To force a deletion, type: $ git branch -D dead_branch # instead of -d Similarly, attempting to overwrite a branch via a move fails if data loss would ensue. To force a branch move, type: $ git branch -M source target # instead of -m Unlike checkout and reset, these two commands defer data destruction. 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). By default, they will be kept for at least two weeks. Clean: Some git commands refuse to proceed because they’re worried about clobbering untracked files. If you’re certain that all untracked files and directories are expendable, then delete them mercilessly with: $ git clean -f -d Next time, that pesky command will work! 38