Curse the sadist who wrote these infernal lines I have no clue whatsoever why anybody would want to do this. Have a cry, checkout your files fresh from origin or remote, and redo your work. In other words, all changes, staged or unstaged, are gone, and your working tree is empty. Now they're removed from your index as well. This then gets piped into the xargs -0 we saw before, which invokes git rm -cached on them, meaning that they get removed from the cache, while the working tree should be left alone - except that you've just removed all files from your working tree. (Hey, didn't we just delete a bunch of stuff?) The option -name-only means you want the (full) file names only and -diff-filter=D means you're interested in deleted files only. Those can be changes between different trees, differences between local copies and remote copies, and so on.Īs used here, it shows the unstaged changes the files you have changed but haven't committed yet. Then we get to git diff, which shows changes between different versions of items git knows about. In other words, "list all files git knows about and remove your local copy". The option -z imposes a specific format on them, the format expected by xargs -0, which then invokes rm -f on them, which means to remove them without checking for your approval. The command git ls-files lists all files git knows about. Git diff -name-only -diff-filter=D -z | xargs -0 git rm -cached Using git reset has been explained, but you asked for an explanation of the piped commands as well, so here goes: git ls-files -z | xargs -0 rm -f Warning: do not use the following command unless you want to lose uncommitted work! When running git status with staged uncommitted file(s), this is now what Git suggests to use to unstage file(s) (instead of git reset HEAD as it used to prior to v2.23). So the older answers with git reset or git reset HEAD are still perfectly valid. This is a new command, but the behaviour of the old commands remains unchanged. With the -staged flag, it restores the content of the working tree from HEAD (so it does the opposite of git add and does not delete any change). Git restore was introduced in July 2019 and released in version 2.23. If you only want to unstage the files in a directory, navigate to it before running the above or run: git restore -staged To unstage all the files in your project, run the following from the root of the repository (the command is recursive): git restore -staged. As pointed out by others in related questions (see here, here, here, here, here, here, and here), you can now unstage a file with git restore -staged.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |