Git –文件操作

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 file

    rm删除文件

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 file

    rm删除指定的文件

  • -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.py

    mv将main.py移至main2.py

LEARN MORE  Vim Editor Commands Cheat-sheet
了解更多Vim编辑器命令备忘单

翻译自: https://www.poftut.com/git-file-operations/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值