Information Technology Reference
In-Depth Information
D m3.txt
?? bar.txt
?? copy.txt
?? new-m3.txt
You can throw away all these changes with two commands:
$ git reset --hard
$ git clean -f
Right now the repository is clean, and you can check it with the $ git status
-s command. All the modifications were lost.
How It Works
You already know the command $ git reset --hard . It resets all the tracked
files to the state saved in the latest revision. But the $ git reset command does
not modify untracked files. To remove all untracked files use the $ git clean -f
command. The parameter -f serves as a precaution; without it, the $ git clean
command only prints a message. It's another level of security that helps to avoid data
loss. However, if you want to just list the files that would have been removed without
actually deleting them use the $ git clean -n command.
5-6. Switching branches in a dirty repos-
itory without conflicts
Problem
Suppose that during your work in the repository, you modified some files and want to
commit them in a branch that is different from your current branch. You have to switch
branches in a dirty repository. Depending on your changes, this operation can be al-
lowed or forbidden by git. In this recipe, we consider the case when switching is al-
lowed.
Search WWH ::




Custom Search