Normal file operations like deleting, moving, changing file name can be done in git.
普通的文件操作,如删除,移动,更改文件名,都可以在git中完成。
删除文件 (Removing File)
A tracked file can be removed liked below.
跟踪的文件可以删除,如下所示。
$ git rm LICENSE
rm 'LICENSE'
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
deleted: LICENSE
rm
removes filerm
删除文件
After remove operation and commit the file will be not tracked and exist for the future commits but exist in the history.
在执行删除操作并提交之后,将不会跟踪该文件,并且该文件对于以后的提交存在,但在历史记录中存在。
If the file is edited we need to force removal with the following command.
如果文件被编辑,我们需要使用以下命令强制删除。
$ git rm README.md
error: the following file has local modifications:
README.md
(use --cached to keep the file, or -f to force removal)
$ git rm -f README.md
rm 'README.md'
rm
removes the specified filerm
删除指定的文件-f
forces for removal even if the file is edited-f
强制删除,即使文件已编辑
移动文件(Moving Files)
Unlike other vcs Git do not tracks files movements for reguler movement. To make Git aware of the movement mv
is used.
与其他vcs不同,Git不会跟踪文件的移动以进行调节器移动。 为了使Git知道运动,使用了mv
。
$ git mv main.py main2.py
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
renamed: main.py -> main2.py
mv
moves main.py to main2.pymv
将main.py移至main2.py