Assuming nothing is staged, what's the recommended way to reset all the work you've done, except for files:
app/models/a.rb app/views/a/index.html.rb config/foo.rb config/bar.rb
Other dirty files exist in app/models/ and app/views/ that I don't want to keep.
git reset --hard resets your index and reverts the tracked files back to state as they are in HEAD. It leaves untracked files alone.
git reset --hard is a classic command in this situation - but it will only discard changes in tracked files (i.e. files that already are under version control). To get rid of new / untracked files, you'll have to use git clean !
To hard reset files to HEAD on Git, use the “git reset” command with the “–hard” option and specify the HEAD. The purpose of the “git reset” command is to move the current HEAD to the commit specified (in this case, the HEAD itself, one commit before HEAD and so on).
Running git reset will typically delete files and commits. And without those, you don't have a project! This is why it's critical to plan ahead when using it, so you don't end up deleting elements that are critical for your project.
As you described the problem, it doesn't look like you want do reset
. The simplest thing for this is:
git add app/models/a.rb app/views/a/index.html.rb config/foo.rb config/bar.rb git checkout .
so, it adds your 4 files into the index, and checks out clean versions (i.e. discards changes) for other files.
I assume you have not staged (git add
) modified files before (you should then unstage it using reset).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With