How does git discard all local modifications


This article mainly introduces how git abandons all local modifications and shares them with you. The details are as follows:

Git checkout. # all local modifications, which are not submitted, return to the original state
Git stash saves all uncommitted changes to stash. It can be recovered with git stash pop.
Git reset -- hard hash # returns to a node without any modification.
Git reset -- soft hash # return to a node and keep the modification.
Git log # you can view the history of GIT commit and its hash ID

Usage of GIT clean

The GIT clean command is used to delete all files that have not been tracked from your working directory

Git clean is often used with git reset — hard. Remember that reset only affects files that have been tracked, so you need clean to delete files that have not been tracked. Using these two commands together can make your working directory return to a specified state completely

git clean -n

It’s a clean exercise to tell you which files will be deleted. Remember that it won’t really delete files, it’s just a reminder.

git clean -f

Delete all the files in the current directory that have not been tracked. It will not delete the folder and files specified in the. Gitignore file, no matter whether they have been tracked or not

git clean -f <path>

Delete the files that have not been tracked in the specified path

git clean -df

Delete files and folders that have not been tracked in the current directory

git clean -xf

Delete all files that have not been tracked in the current directory, no matter whether it is the folder and file specified in the. Gitignore file or not

git reset --hard and git clean -f It’s a good pair of friends. Using them together can make your working directory completely return to the last commit time

git clean It is also very useful for newly compiled projects. For example, it can easily delete the. O and. Exe files generated after compilation. This is very useful when packaging and releasing a release

The following example will delete all the changes under the working directory, including the newly added files. Suppose you have submitted some snapshots and made some new development

git reset --hard

git clean -df

After running, the working directory and the cache will return to the same state as the last commit. Git status will tell you that this is a clean working directory and a new start!

This article about git how to give up all local modification method is introduced here. For more related git give up all local modification content, please search previous articles of developer or continue to browse the following related articles. I hope you can support developer more in the future!