本文git版本1.9.6git
git代码提交层次图bash
1、修改本地代码查看差别ide
2、移除代码ui
3、重命名代码3d
1.一、当咱们修改本地code的时候,使用命令能够看到文件的状态的处于修改状态;而后咱们能够将code add 而后进行commit;code
咱们能够看到code修改什么地方,修改了什么内容;blog
$ git status -s $ echo 'puts "hello world!"' >> hello.rb $ git diff hello.rb
1.二、将此添加到staging area区域,再次查看文件状态ip
$ git add hello.rb $ git status -s $ git diff hello.rb
能够看到文件状态表示staging area和repository区域之间发生了改变;get
能够看出 diff 选项 能够用于查看working directory 和 staging area 区域间的文件变化;it
1.三、使用 git diff HEAD 能够看到 working directory 和 repository 区域间 的文件变化
$ git diff HEAD hello.rb
1.四、使用git diff --staged 能够看到 staging area 和 repository 区域间的文件变化
$ git diff --staged hello.rb
$ git diff --staged --stat hello.rb # 输出简要信息
这是文件改变输出变化的命令
二、移除代码
2.一、将hello.rb的文件删除,(此步至关于 add 的逆操做)查看文件状态;将结果 commit 到 repository;查看文件状态;
$ git rm hello.rb $ ls $ git status -s
能够看出执行 rm 的时候就已经将本地文件删除掉了;
执行 status 能够看到文件状态标识为 D 表示处理已删除状态;
$ git commit -m "first del" hello.rb
2.二、若是咱们不想删除working directory 区域的文件,只想删除 staging area 区域的文件,能够执行 git rm --cached 命令;
$ git rm --cached hello.rb
在执行 git status -s 后,D 和 ?? 是什么意思呢? D 表示 staging area 和 repository 区域的差异,表示 hello.rb 处理删除状态, 因此在working directory 区域的 hello.rb就处于 Untracked 状态;
2.三、若是想恢复staging area 区域的hello.rb,能够从repository 拉取 或 从 working directory 提交上去 (在本地没有改变的时候,若是改变,那提交的是新文件,也不会恢复到以前的文件);
$ git reset hello.rb # 从 repository 拉取
三、重命名代码
3.一、将本地文件 README.txt 重命名为 README.md ;查看文件状态,而后提交到 repository ;
$ git mv README.txt README.md $ git commit -m "first rename filename"
tips: 上面 执行 commit 的时候,实际上是执行了两个步骤,把 README.txt 删除提交,把 README.md 提交; 看下图就明白了;
其实在 git 中,文件的名字和内容能够分开理解(就像 Python 的 变量和值);在git中,若是两个文件的内容同样,他就认为是一个重命名;