DevNet Associate DEVASC 200-901 Official Certification Guide by Adrian Iliesiu (z-lib.org)

(andrew) #1
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)

new file: newfile

Removing files and directories from Git is not as simple
as just deleting them from the directory itself. If you just
use file system commands to remove files, you may
create headaches as the index can become confused. You
can remove files and directories from Git, but it requires
an extra step of adding the file deletion to the index
(which sounds counterintuitive, right?). The best way is
to use the git rm command, which has the following
syntax:


Click here to view code image


git rm (-r) (-f) (folder/file.py)

This command removes a file or directory and syncs it
with the index in one step. If you want to remove a
directory that is not empty or has subdirectories, you can
use the -r option to remove recursively. In addition, if
you add a file to Git and then decide that you want to
remove it, you need to use the -f option to force removal
from the index. This is required only if you haven’t
committed the changes to the local repository. Here is an
example:


# touch removeme.py
# git add.
# ls
newfile removeme.py
# git rm -f removeme.py
rm 'removeme.py'

git mv is the command you use to move or rename a file,
directory, or symbolic link. It has the following syntax:

Free download pdf