您当前的位置: 首页 > 学无止境 > 心得笔记 网站首页心得笔记
06 给文件重命名的简便方法
发布时间:2020-07-04 11:43:11编辑:雪饮阅读()
在git中标准的文件重命名流程
$ mv index.html index.html2
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/web (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
deleted: index.html
Untracked files:
(use "git add <file>..." to include in what will be committed)
index.html2
no changes added to commit (use "git add" and/or "git commit -a")
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/web (master)
$ git add index.html
index.html index.html2
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/web (master)
$ git add index.html2
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/web (master)
$ git rm index.html
rm 'index.html'
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/web (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
renamed: index.html -> index.html2
工作区及暂存区的还原
在本次操作没有commit时可以通过git reset –hard来还原工作区(暂存区同时也会自动被清理掉)
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/web (master)
$ git reset --hard
HEAD is now at 48142d3 modified index.html
Git中文件命名的简便方法
上面演示了git中文件命名的标准流程,该流程步骤比较繁多,其实git还可以通过命令git mv file newfile的方式快速的重命名,该重命名后会自动完成上面标准重命名操作步骤直接到达暂存区处理完毕的状态。
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/web (master)
$ git mv index.html index.html2
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/web (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
renamed: index.html -> index.html2
关键字词:git,文件重命名