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

简介: ⑥. 删除文件 rm⑦. 提交到版本库、形成历史版本 commit

⑥. 删除文件 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



相关文章
|
9天前
|
开发工具 git
使用Git根据日期进行代码版本切换的方法
通过以上步骤,可以有效地根据日期进行Git代码版本的切换。这种方法在需要回溯历史版本进行bug修复或功能复查时特别有用。Git的灵活性和强大功能使其成为现代软件开发不可或缺的工具之一。
210 103
|
20天前
|
安全 开发工具 git
git添加远程仓库报错To add an exception for this directory解决方案-优雅草卓伊凡
git添加远程仓库报错To add an exception for this directory解决方案-优雅草卓伊凡
139 5
git添加远程仓库报错To add an exception for this directory解决方案-优雅草卓伊凡
|
1月前
|
开发工具 git 开发者
Git版本管理常见文件提交流程讲解
以上就是Git常见文件提交流程概述。掌握此流程对于任何使用Git进行版本控制和协同工作项目团队成员都至关重要。
90 13
|
3月前
|
开发工具 git
使用Git下载指定版本或指定commit
使用Git下载指定版本或指定commit
|
7月前
|
开发工具 git 索引
warning: You ran ‘git add’ with neither ‘-A (—all)’ or ‘—ignore-removal’,报错如何解决 git报错 ‘git add —ignore-removal <pathspec>优雅草卓伊凡
warning: You ran ‘git add’ with neither ‘-A (—all)’ or ‘—ignore-removal’,报错如何解决 git报错 ‘git add —ignore-removal <pathspec>优雅草卓伊凡
112 21
warning: You ran ‘git add’ with neither ‘-A (—all)’ or ‘—ignore-removal’,报错如何解决 git报错 ‘git add —ignore-removal <pathspec>优雅草卓伊凡
|
7月前
|
安全 开发工具 Android开发
【Android Git】Git版本回退方式
在实际操作中,选择合适的版本回退方式,可以有效地管理代码版本,提高开发效率和代码质量。
422 26
|
7月前
|
IDE 开发工具 git
pycharm如何查看git历史版本变更信息
通过上述步骤,你可以在 PyCharm 中轻松查看 Git 的历史版本变更信息,无论是针对整个项目、特定文件还是分支。使用 PyCharm 的 Git 集成功能,可以更高效地管理和审查代码变更,提高开发过程的透明度和可维护性。
476 19
|
8月前
|
开发工具 git 索引
怎么取消对project.private.config.json这个文件的git记录
通过以上步骤,您可以成功取消对 `project.private.config.json`文件的Git记录。这样,文件将不会被包含在未来的提交中,同时仍保留在您的工作区中。
227 28
|
9月前
|
前端开发 Java 开发工具
Git使用教程-将idea本地Java等文件配置到gitte上【保姆级教程】
本内容详细介绍了使用Git进行版本控制的全过程,涵盖从本地仓库创建到远程仓库配置,以及最终推送代码至远程仓库的步骤。
508 0
|
开发工具 git 索引
git上面中新建gitignore文件,并且去除已经在仓库版本管理中的文件夹
git上面中新建gitignore文件,并且去除已经在仓库版本管理中的文件夹
363 4