git 命令 git status add rm commit mv
1.查看 git 仓库文件改动状态
Git 仓库内文件改动有 4 种状态,除了 Unmodified 状态的文件因为并未改动默认没有状态不做显示之外,其他文件改动状态都可以通过 git status 来查看
查看 Git 记录的状态 常用命令,
查看git仓库状态
git status
拿到一个git仓库,进入仓库,第一执行这个命令查看
[root@ci-node1 ~]# cd /data/git_test/
[root@ci-node1 git_test]#
[root@ci-node1 git_test]# git status
On branch master // 在master分支上 默认在master分支上 Initial commit // 初始化commit nothing to commit (create/copy files and use "git add" to track)
// 现在是空仓库 你可以创建,拷贝文件然后可以使用git add 命令
在工作区创建 a、b、c 三个文件。
[root@ci-node1 git_test]# touch a b c
[root@ci-node1 git_test]# ll
total
-rw-r--r-- root root Aug : a
-rw-r--r-- root root Aug : b
-rw-r--r-- root root Aug : c
看 Git 记录的状态,从下面结果可知,新增的 3 个文件在 Git 空间里都属于Untracked 文件,存放在工作区内
[root@ci-node1 git_test]# git status
On branch master Initial commit Untracked files:
(use "git add <file>..." to include in what will be committed) a
b
c nothing added to commit but untracked files present (use "git add" to track)
Git 仓库目录下的文件改动操作默认都发生在 Git 工作区内,Git 并不会主动管理。如果希望 Git 能够管理这些变动,你需要主动通知 Git。共有 3 种通知 Git 的命令(git add/rm/mv)
2. 将工作区文件改动添加到暂存区 git add
git add是第一种通知Git命令,这个命令用于告诉Git我们新增了文件改动,被git add命令操作过的文件(改动)便会处于 Git 暂存区
[root@ci-node1 git_test]# git add a // 添加单文件改动到暂存区
[root@ci-node1 git_test]# git status // 查看此时的文件状态,a 文件已在暂存区中了
On branch master Initial commit Changes to be committed:
(use "git rm --cached <file>..." to unstage) new file: a Untracked files:
(use "git add <file>..." to include in what will be committed) b
c
git add 把一个文件从工作目录移动到暂存区,从Untracked 状态到Staged状态
暂存区是在.git目录下index文件,初始化仓库时候index文件不存在,当使用git add 把文件移动到暂存区这个index文件就生成了
[root@ci-node1 git_test]# cd .git/
[root@ci-node1 .git]# ll
total
drwxr-xr-x root root Aug : branches
-rw-r--r-- root root Aug : config
-rw-r--r-- root root Aug : description
-rw-r--r-- root root Aug : HEAD
drwxr-xr-x root root Aug : hooks
-rw-r--r-- root root Aug : index // index文件生成
drwxr-xr-x root root Aug : info
drwxr-xr-x root root Aug : objects
drwxr-xr-x root root Aug : refs
我们可以使用 git add . git add * 可以一次将多个文件改动添加到暂存区
把工作目录所有文件都提交到暂存区
[root@ci-node1 git_test]# git add .
输出结果
// 查看此时的文件状态,3 个文件都已在暂存区中了 [root@ci-node1 git_test]# git status
On branch master Initial commit Changes to be committed:
(use "git rm --cached <file>..." to unstage) new file: a
new file: b
new file: c
3.将暂存区文件改动回退 git rm
Git rm 命令用于告诉 Git 我们想把之前用 git add 添加的文件改动从 Git 暂存区里拿出去,不需要 Git 记录了。拿出去有两种拿法,一种是从暂存区退回到工作区,另一种是直接丢弃文件改动。让我们试着将 c 退回到工作区,b 直接丢弃。
git rm 将文件从暂存区移回到工作目录,使状态Staged变成unstaged
git rm --cached
git rm -f
git rm --cached
//将 c 的改动从暂存区工作区
//将 c 的改动从暂存区工作区
[root@ci-node1 git_test]# git rm --cached c
rm 'c'
//查看 c 是否已经移回工作区
[root@ci-node1 git_test]# git status
On branch master Initial commit Changes to be committed:
(use "git rm --cached <file>..." to unstage) new file: a
new file: b Untracked files:
(use "git add <file>..." to include in what will be committed) c
git rm -f
//将 b 文件直接从 git 空间里删除,也是就是从暂存区和工作区都删除。
//将 b 文件直接从 git 空间里删除,也是就是从暂存区和工作区都删除。
[root@ci-node1 git_test]# git rm -f b
rm 'b' //查看状态
[root@ci-node1 git_test]# git status
On branch master Initial commit Changes to be committed:
(use "git rm --cached <file>..." to unstage) new file: a Untracked files:
(use "git add <file>..." to include in what will be committed) c //当前目录中已经没有文件 b
[root@ci-node1 git_test]# ll
total
-rw-r--r-- root root Aug : a
-rw-r--r-- root root Aug : c
4.提交 git commit
把文件从暂存区提交到本地仓库
当我们在仓库工作区下完成了文件增删改操作之后,并且使用 git add 将文件改动记录在暂存区之后,便可以开始将其提交到 Git 本地仓库。
将暂存区内容提交 git commit –m “”
后面的“”是描述,描述这次提交内容是什么
[root@ci-node1 git_test]# git status
On branch master Initial commit Changes to be committed:
(use "git rm --cached <file>..." to unstage) new file: a
//将暂存区内的文件 a.txt 提交到本地仓库
//将暂存区内的文件 a.txt 提交到本地仓库
root@ci-node1 git_test]# git commit -m "commit a"
[master (root-commit) 73d7230] commit a
file changed, insertions(+), deletions(-)
create mode a // 查看工作区状态,现在工作区是干净的工作区,可以理解为工作目录、
//缓存区、本地仓库三个区域都存储内存是一样的,git三个区域缓存区、工作目录、本地仓库都保存着a文件,a文件在三个区域是一致的
[root@ci-node1 git_test]# git status
On branch master
nothing to commit, working tree clean // a文件被提交到本地仓库了,a文件才真正被git管理
提交到本地仓库的文件在三个区域 工作目录,暂存区,本地仓库 分别存储一份,副本
5.将暂存区文件移动位置/重命名 git mv
Git mv 命令用于告诉 Git 我们想把之前用 git add 添加的文件直接在暂存区里重新命名或移动到新位置。
git mv 对缓存区和工作目录的文件命名和移动到新位置
//将 a 文件改名为 a.txt
//将 a 文件改名为 a.txt
[root@ci-node1 git_test]# git mv a a.txt
[root@ci-node1 git_test]# git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage) renamed: a -> a.txt // 直接告诉状态renamed [root@ci-node1 git_test]# ll
total
-rw-r--r-- root root Aug : a.txt
再提交
[root@ci-node1 git_test]# git commit -m "rename a to a.txt"
[master cc8bd80] rename a to a.txt
file changed, insertions(+), deletions(-)
rename a => a.txt (%) [root@ci-node1 git_test]# git status
On branch master
nothing to commit, working tree clean
git 命令 git status add rm commit mv的更多相关文章
- git命令——git rm、git mv
git rm git rm命令官方解释 删除的本质 在git中删除一个文件,本质上是从tracked files中移除对这些文件的跟踪.更具体地说,就是将这些文件从staging area移除.然后c ...
- git基本命令--status, add, diff, commit, log
git status: git status命令的输出十分详细,但其用语有些繁琐. 如果你使用 git status -s 命令或 git status --short 命令,你将得到一种更为紧凑的格 ...
- git命令——git commit
功能 将暂存区中的更改记录到仓库. 加到staging area里面的文件,是表示已经准备好commit的.所以在commit修改之前,务必确定所有修改文件都是staged的.对于unstaged的文 ...
- git命令——git status、git diff
前言 当对项目做了更改时,我们通常需要知道具体改了哪些文件,哪些文件更改了没有暂存,哪些文件改了并且已加入到暂存区等待下次commit.上述任务使用git status都可以帮我们解决.但是想要知道文 ...
- git命令——git add
如何理解git add git add命令本身并不复杂,字面意义上理解是“将一个文件添加到项目中“.但是这种理解有缺陷,有时候可能会出现某个文件同时存在暂存区域 和 非暂存区域(staged and ...
- Git命令git update-index --assume-unchanged,忽略不想提交的文件(忽略跟踪)
场景 我们在自己的私有测试分支上调试项目逻辑,给文件做了一些特定的修改,但是文件不想被git提交,不想执行git status命令时出现在modified列表里:再比如,我们本地的数据库和测试环境的数 ...
- git 命令 git diff 查看 Git 区域文件的具体改动
查看 Git 区域文件的具体改动 git diff git status 只能让我们知道文件在 Git 区域内的改动状态,但如果我们想查看某个文件内具体改了什么(也可以理解为在不同 Git 区域中的差 ...
- git命令--git checkout 之 撤销提交到暂存区的更改
SYJ@WIN-95I6OG3AT1N /D/gitlab/ihr-kafka-produce (master) $ git status [由于工作区文件被修改了,所以显示为红色] On branc ...
- git命令——git log
功能 在提交了若干更新,又或者克隆了某个项目之后,你也许想回顾下提交历史. 完成这个任务最简单而又有效的方法是 使用git log 命令. 参数 不带任何参数 $ git log commit ca8 ...
随机推荐
- 解决CMD控制台乱码问题
在cmd控制台中出现乱码情况如下 解决方式1 在控制台中输入 CHCP65001 按enter回车键查看 注:CHCP是一个计算机指令,能够显示或设置活动代码页编号. 代码页 描述6500 ...
- MySQL基础练习---牛客网的数据以及典型题目
1 部门表departments 部门no和部门名称 2 部门员工表 dept_emp 每个部门对应的员工信息 3 部门经理表 dept_manager 每个部门的经理信息 4 员工表 employe ...
- 初入SG-UAP
初入SG-UAP SpriderMan 关注 2019.06.19 14:10 字数 1130 阅读 10评论 0喜欢 0 初次接触SG-UAP,将自己的见解以文字形式记录下来,希望能对初入的伙伴们有 ...
- 路由器配置——基于区域的OSPF简单认证
一.实验目的:掌握区域的OSPF简单认证 二.拓扑图: 三.具体步骤配置: (1)R1路由器配置 Router>enable Router#configure terminal Enter co ...
- Cogs 647. [Youdao2010] 有道搜索框(Trie树)
[Youdao2010] 有道搜索框 ★☆ 输入文件:youdao.in 输出文件:youdao.out 简单对比 时间限制:1 s 内存限制:128 MB [问题描述] 在有道搜索框中,当输入一个或 ...
- P2699 【数学1】小浩的幂次运算
原题链接 https://www.luogu.org/problemnew/show/P2699 P2699 [数学1]小浩的幂次运算 首先第一眼看这个题就知道要暴力枚举w^i 看是否在区间[l,r] ...
- ie浏览器中时间转换
var begintime = $("#start").val(); var lastLoginTimeStart =new Date(begintime).getTime();/ ...
- 安装mongodb-window10版
第一.下载mongodb 官方地址:https://www.mongodb.com/ 第二步mongodb安装 运行mongodb-win32-x86_64-2008plus-ssl-v3.4-lat ...
- 2016 Multi-University Training Contest 3 部分题解
1001,只要枚举区间即可.签到题,要注意的是输入0的话也是“TAT”.不过今天补题的时候却WA了好几次,觉得奇怪.原来出现在判断条件那里,x是一个int64类型的变量,在进行(x<65536* ...
- elasticsearch Delete (根据条件删除)
之前在 2.X版本里 这个Delete By Query功能被去掉了 因为官方认为会引发一些错误 如需使用 需要自己安装插件. bin/plugin install delete-by-query 需 ...