且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

GIT03_初始化init、看状态status、添加add、删除rm、commit提交、历史版本reflog、忽略文件gitignore(三)

更新时间:2022-06-02 05:22:58

⑥. 删除文件 rm


  • ①. git rm 删除文件(删除的是提交到本地库的文件)
    注意:上面删除的只是工作区的文件,需要提交到本地仓库


  • ②. 如下代码删除后,我们需要重新进行commit操作


$ git add b.txt
warning: LF will be replaced by CRLF in b.txt.
The file will have its original line endings in your working directory
Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master)
$ git commit -m "b.txt" b.txt
warning: LF will be replaced by CRLF in b.txt.
The file will have its original line endings in your working directory
[master 4ae6a0c] b.txt
 1 file changed, 1 insertion(+)
 create mode 100644 b.txt
Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master)
$ git status
On branch master
nothing to commit, working tree clean
Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master)
$ git rm b.txt
rm 'b.txt'
Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master)
$ git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        deleted:    b.txt


Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master)
$ git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        deleted:    b.txt
# 注意这里需要重新提交操作
Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master)
$ git commit -m "delete b.txt"
[master d39bee4] delete b.txt
 1 file changed, 1 deletion(-)
 delete mode 100644 b.txt
Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master)
$ git status
On branch master
nothing to commit, working tree clean


⑦. 提交到版本库、形成历史版本 commit


  • ①. git commit -m “日志信息” 文件名(272a9cd这个是版本号)


  • ②. 从工作目录一步提交到版本库:git commit -am ‘new project’(加入缓存区并提交[一步到位])


$ git add -A
warning: LF will be replaced by CRLF in a.txt.
The file will have its original line endings in your working directory
Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master)
$ git status
On branch master
No commits yet
Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   a.txt
Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master)
$ git commit -m "第一次提交 a.txt" a.txt
warning: LF will be replaced by CRLF in a.txt.
The file will have its original line endings in your working directory
[master (root-commit) 272a9cd] 第一次提交 a.txt
 1 file changed, 9 insertions(+)
 create mode 100644 a.txt
Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master)
$ git status
On branch master
nothing to commit, working tree clean