I'm still not even quite sure how to a) discard edits that I've made but not added/committed yet and b) delete something from a repo that I added accidentally.
git checkout somefile
will discard edits which you've not added to the index. This command is destructive of course. git rm -f somefile
will delete a file from the repo (you then have to commit the change). If you want to permanently delete a file, including from history, eg because it contains a password, that's a bit more difficult, but possible in some circumstances.I can also recommend these two aliases I have in my gitconfig:
unstage = reset HEAD --
undo = reset --soft HEAD^
`unstage` takes an argument and removes changes from the index (but keeps them in the file). `undo` undos the last commit and puts the changes into the index.
Unstage you pass a file or `.` for allgit rm <file> to delete something you've added accidentally