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添加远程仓库报错To add an exception for this directory解决方案-优雅草卓伊凡
git添加远程仓库报错To add an exception for this directory解决方案-优雅草卓伊凡
864 5
git添加远程仓库报错To add an exception for this directory解决方案-优雅草卓伊凡
|
10月前
|
开发工具 git 开发者
Git版本管理常见文件提交流程讲解
以上就是Git常见文件提交流程概述。掌握此流程对于任何使用Git进行版本控制和协同工作项目团队成员都至关重要。
383 13
|
开发工具 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>优雅草卓伊凡
334 21
warning: You ran ‘git add’ with neither ‘-A (—all)’ or ‘—ignore-removal’,报错如何解决 git报错 ‘git add —ignore-removal <pathspec>优雅草卓伊凡
|
开发工具 git 索引
怎么取消对project.private.config.json这个文件的git记录
通过以上步骤,您可以成功取消对 `project.private.config.json`文件的Git记录。这样,文件将不会被包含在未来的提交中,同时仍保留在您的工作区中。
420 28
|
前端开发 Java 开发工具
Git使用教程-将idea本地Java等文件配置到gitte上【保姆级教程】
本内容详细介绍了使用Git进行版本控制的全过程,涵盖从本地仓库创建到远程仓库配置,以及最终推送代码至远程仓库的步骤。
2127 0
|
开发工具 git
Git基础 3 ---- Git 初始化及仓库创建
 1 Git基础设置    1 设置用户名       git config --global user.name "用户名"           2 设置用户邮箱       git config --global user.
1231 0
|
10月前
|
开发工具 git
Git版本控制工具合并分支merge命令操作流程
通过以上步聚焦于技术性和操作层面指南(guidance), 可以有效管理项目版本控制(version control), 并促进团队协作(collaboration).
2646 15
|
安全 开发工具 git
git的常用操作命令
git的常用操作命令
752 57
|
人工智能 前端开发 Java
用git rebase命令合并开发阶段中多条commit提交记录
通过 `git rebase`,可以合并多个提交记录,使开发历史更简洁清晰。操作分为 6 步:查看提交历史 (`git log --oneline`)、设置需合并的提交数 (`git rebase -i HEAD~N`)、修改动作标识为 `s`(squash)、保存退出编辑、调整提交信息、强制推送至远程仓库 (`git push -f`)。此方法适合清理本地无关提交,但若有团队协作或冲突风险,需谨慎使用以避免问题。
2754 60