4 ms·
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.
by pbreit 11y ago
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.
- rwmj 11y agogit 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.
- K0nserv 11y agogit checkout <file> to discard. This will checkout the full file to latest version tracked. Alternatively If you wanna save some of the file you can use git add -p <file> and stage the individual parts you want. After you've committed those you can checkout the file. git rm <file> to delete something you've added accidentally
- rndstr 11y agoa) You can also use `git checkout -p` here that lets you selectively revert patches 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 all