I have deleted about 20 files from my project. How to commit them with one command instead of git rm <filename>
them one by one?
If you have deleted the file and already committed the changes, you need to use the ` git checkout` command to restore the file. First, you need to find out the checksum of the commit that deleted the file, and then check out the file from the previous commit.
By default, the git rm command deletes files both from the Git repository as well as the filesystem. Using the --cached flag, the actual file on disk will not be deleted.
OPTIONS. Files to remove. A leading directory name (e.g. dir to remove dir/file1 and dir/file2 ) can be given to remove all files in the directory, and recursively all sub-directories, but this requires the -r option to be explicitly given. The command removes only the paths that are known to Git.
If you don't want to commit all other changes in your working directory at the same time (as git add -A
would do), you can use
git rm $(git ls-files --deleted)
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