I'm trying to learn Git. I'm confused between
git rm --cached file
and
git reset file
both of the commands seem to take the file from staged to un-staged area. How do the commands differ?
git rm —cached file will remove the file from the stage. That is, when you commit the file will be removed. git reset HEAD — file will simply reset file in the staging area to the state where it was on the HEAD commit, i.e. will undo any changes you did to it since last commiting.
The Git rm –cached flag removes a file from the staging area. The files from the working directory will remain intact. This means that you'll still have a copy of the file locally. The file will be removed from the index tracking your Git project.
If you've run only git rm -r --cached , try doing a git reset HEAD . from within your repo root. If you did a git commit -m "msg" after doing a git rm -r --cached , i.e., you committed the changes, then do git reset HEAD~1 to undo your last commit.
git rm will remove the file from the index and working directory ( only index if you used --cached ) so that the deletion is staged for next commit.
git rm --cached <file>
will completely remove the file's contents from the index. This means that on commit the file will be removed from the HEAD
commit. (If the file was only added to the index and not yet tracked this is a "no-op".)
git reset -- <file>
resets the contents of the file in the index to be the same as the head commit. This means that on commit no changes will be committed to the file. This operation is not valid if there is no tracked version of the file in the HEAD
commit.
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