I’d like to know if there’s a easy (built-in) way to when reverting to an old commit, delete all the files that were created since that commit, even if they weren’t added to the repository.
Let’s say I have a directory D and have made a commit C over D. If I now add to directory D a new file F and wish to revert do C, F won’t be deleted from the directory.
Is there any easy way to prevent this behaviour?
I’m a little confused by your example, but this command:
will remove all untracked and ignored files and subdirectories from
<directory>. (Make sure you really mean it!) The-xmakes it delete ignored files, and the-dmakes it delete directories – remove those if you don’t want to do that. The-fis required for it to do anything, since it’s so scary – you can also use-nfor a “dry run”.In combination with
git reset --hard, this can be used to get you to exactly the state of the current commit.There’s no way to make Git do this automatically, since it’d be absolutely terrifying – you might forget to commit a file, then blow it away.