git mv

行为:

  1.创建一个和之前文件内容一样的文件,文件名为新的文件名

  2.将原来的文件删除

  3.将删除的文件添加到暂存区

  4.将新建的文件添加到暂存区

$ git mv a a1
$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)
  renamed: a -> a1

提交:

  直接 git commit -m ''

$ git commit -m 'rename a to a1'
[master 863356d] rename a to a1
  1 file changed, 0 insertions(+), 0 deletions(-)
  rename a => a1 (100%)
$ git status
  On branch master
  nothing to commit, working directory clean

恢复:

  1. 恢复暂存区(git reset HEAD oldName)

  2. 将新添加的文件从暂存区移除(git reset HEAD newName)

  3. 将原来的文件从暂存区恢复到工作区(git checout -- oldName)

  3. 从工作区删除新添加的这个文件(rm newName)

$ git reset HEAD a
Unstaged changes after reset:
D a $ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage) new file: a1 Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory) deleted: a $ git reset HEAD a1
Unstaged changes after reset:
D a $ git status
On branch master
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory) deleted: a Untracked files:
(use "git add <file>..." to include in what will be committed) a1 no changes added to commit (use "git add" and/or "git commit -a") $ git checkout -- a $ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed) a1 nothing added to commit but untracked files present (use "git add" to track) $ rm a1 $ git status
On branch master
nothing to commit, working directory clean

直接调用系统的mv

行为:

  只是重命名了一个文件

$ mv a a1

$ git status
On branch master
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory) deleted: a Untracked files:
(use "git add <file>..." to include in what will be committed) a1 no changes added to commit (use "git add" and/or "git commit -a")

提交:

  1.把新文件和旧文件加入暂存区

  2.提交暂存区的改动

$ git add a a1

$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage) renamed: a -> a1 $ git commit -m 'rename a to a1'
[master 8b02e6a] rename a to a1
file changed, insertions(+), deletions(-)
rename a => a1 (%) $ git status
On branch master
nothing to commit, working directory clean

恢复:

  1.将旧文件恢复到工作区,git checout -- oldName

  2.将新文件删除, rm newName

$ git checkout -- a
$ rm a1 $ git status
On branch master
nothing to commit, working directory clean

git mv与直接mv的区别的更多相关文章

  1. git 学习笔记5--rm & mv,undo

    rm 删除文件 rm <file> #Unix删除文件 git rm <file> # git删除文件 git rm -f <file> # git强制删除文件 g ...

  2. git database 数据库 平面文件 Git 同其他系统的重要区别 Git 只关心文件数据的整体是否发生变化,而大多数其他系统则只关心文件内容的具体差异 Git 的设计哲学

    小结: 1.如果要浏览项目的历史更新摘要,Git 不用跑到外面的服务器上去取数据回来 2.注意 git clone  应指定版本,它复制的这个版本的全部历史信息: 各个分支  git init 数据库 ...

  3. gitLab的使用 和 git 、 github、gitlab的区别

    一.git . github.gitlab的区别  (百度相关内容得到的理解) ​ ​ 二.git最基本作用:版本控制 ​ 三.有集成了git的GIT安装包 github和gitlab都使用git该版 ...

  4. 关于git和SVN的介绍和区别

    主要对git,svn进行一个简单的介绍. 顺带,我会在后面把我整理的一整套CSS3,PHP,MYSQL的开发的笔记打包放到百度云,有需要可以直接去百度云下载,这样以后你们开发就可以直接翻笔记不用百度搜 ...

  5. 浅谈Linux下mv和cp命令的区别

    1.功能上的区别 mv:用户可以使用该命令为文件或目录重命名或将文件由一个目录移入另一个目录中. cp: 该命令的功能是将给出的文件或目录拷贝到另一文件或目录中. 2.从inode角度来区分 mv:会 ...

  6. 对比git rm和rm的使用区别

    在这里说一下git rm和rm的区别,虽然觉得这个问题有点肤浅,但对于刚接触git不久的朋友来说还是有必要的. 用 git rm 来删除文件,同时还会将这个删除操作记录下来:用 rm 来删除文件,仅仅 ...

  7. git和其他版本控制系统的区别

    所有除了Git以外的版本控制系统都使用增量存储方式来保存不同版本,而Git则在每一个commit时,保存一个整个文件的content copy,除非那个文件没有做过改动.Git和其他版本系统的主要区别 ...

  8. git commit -m与-am的区别

    前面的话 使用git commit -am是不是就可以完全不使用git add命令呢?不是 理论 要了解git commit -m与git commit -am的区别,首先要明白它们的定义 字面解释的 ...

  9. Git分支merge和rebase的区别

    Git merge是用来合并两个分支的. git merge b # 将b分支合并到当前分支 同样 git rebase b,也是把 b分支合并到当前分支 原理 如下: 假设你现在基于远程分支&quo ...

随机推荐

  1. lockf函数的使用

    #include<stdio.h> #include<unistd.h> void main() {int p1,p2,i; while((p1=fork())==-1);// ...

  2. Hibernate Annotation 字段 默认值

    http://emavaj.blog.163.com/blog/static/133280557201032262741999/ ——————————————————————————————————— ...

  3. Spring Cloud对于中小型互联网公司来说是一种福音

    Spring Cloud对于中小型互联网公司来说是一种福音,因为这类公司往往没有实力或者没有足够的资金投入去开发自己的分布式系统基础设施,使用Spring Cloud一站式解决方案能在从容应对业务发展 ...

  4. Servlet采用多线程来处理多个请求同时访问

    Servlet采用多线程来处理多个请求同时访问,Servlet容器维护了一个线程池来服务请求.

  5. sudo执行脚本找不到环境变量解决方法

    问题: 当普通用户下,设置并export一个变量,然后利用sudo执行echo命令,能得到变量的值,但是如果把echo命令写入脚本, 然后再sudo执行脚本,就找不到变量,未能获取到值. 原因 sud ...

  6. java泛型之泛型边界

    http://blog.csdn.net/renwuqiangg/article/details/51296621

  7. 系统之间通讯方式—SOAP(web service)

    [web service 简介] 是一种新的web应用程序分支,是自包含.自描述.模块化的应用,可以发布.定位.通过web调用.web service是一个应用组件,它逻辑性的为其他应用程序提供数据与 ...

  8. 剑指 offer set 24 扑克牌的顺子

    题目 从扑克牌中任意抽取出 5 张牌, 判断是不是顺子, 并且大小王可以看成任意的数字 思路 1. 把大小王当做 0 插入到数组中, 然后对数组排序 2. 统计相邻两个数之间的空隙数, 若空隙数大于 ...

  9. EF简单查询

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  10. 苹果发布【新开发语言】Swift

    Swift is a multi-tenant, highly scalable and durable object storage system that was designed to stor ...