git mv

行为:

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

  2.将原来的文件删除

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

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

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

提交:

  直接 git commit -m ''

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

恢复:

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

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

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

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

  1. $ git reset HEAD a
  2. Unstaged changes after reset:
  3. D a
  4.  
  5. $ git status
  6. On branch master
  7. Changes to be committed:
  8. (use "git reset HEAD <file>..." to unstage)
  9.  
  10. new file: a1
  11.  
  12. Changes not staged for commit:
  13. (use "git add/rm <file>..." to update what will be committed)
  14. (use "git checkout -- <file>..." to discard changes in working directory)
  15.  
  16. deleted: a
  17.  
  18. $ git reset HEAD a1
  19. Unstaged changes after reset:
  20. D a
  21.  
  22. $ git status
  23. On branch master
  24. Changes not staged for commit:
  25. (use "git add/rm <file>..." to update what will be committed)
  26. (use "git checkout -- <file>..." to discard changes in working directory)
  27.  
  28. deleted: a
  29.  
  30. Untracked files:
  31. (use "git add <file>..." to include in what will be committed)
  32.  
  33. a1
  34.  
  35. no changes added to commit (use "git add" and/or "git commit -a")
  36.  
  37. $ git checkout -- a
  38.  
  39. $ git status
  40. On branch master
  41. Untracked files:
  42. (use "git add <file>..." to include in what will be committed)
  43.  
  44. a1
  45.  
  46. nothing added to commit but untracked files present (use "git add" to track)
  47.  
  48. $ rm a1
  49.  
  50. $ git status
  51. On branch master
  52. nothing to commit, working directory clean

直接调用系统的mv

行为:

  只是重命名了一个文件

  1. $ mv a a1
  2.  
  3. $ git status
  4. On branch master
  5. Changes not staged for commit:
  6. (use "git add/rm <file>..." to update what will be committed)
  7. (use "git checkout -- <file>..." to discard changes in working directory)
  8.  
  9. deleted: a
  10.  
  11. Untracked files:
  12. (use "git add <file>..." to include in what will be committed)
  13.  
  14. a1
  15.  
  16. no changes added to commit (use "git add" and/or "git commit -a")

提交:

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

  2.提交暂存区的改动

  1. $ git add a a1
  2.  
  3. $ git status
  4. On branch master
  5. Changes to be committed:
  6. (use "git reset HEAD <file>..." to unstage)
  7.  
  8. renamed: a -> a1
  9.  
  10. $ git commit -m 'rename a to a1'
  11. [master 8b02e6a] rename a to a1
  12. file changed, insertions(+), deletions(-)
  13. rename a => a1 (%)
  14.  
  15. $ git status
  16. On branch master
  17. nothing to commit, working directory clean

恢复:

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

  2.将新文件删除, rm newName

  1. $ git checkout -- a
  2. $ rm a1
  3.  
  4. $ git status
  5. On branch master
  6. 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. thinkphp 命名规范

    目录和文件命名 目录和文件名采用 小写+下划线,并且以小写字母开头: 类库.函数文件统一以.php为后缀: 类的文件名均以命名空间定义,并且命名空间的路径和类库文件所在路径一致(包括大小写): 类名和 ...

  2. BI开发之——Mdx基础语法(转至指尖流淌)

    Mdx为MultiDimensional  Expressions的缩写,多维表达式,是标准的OLAP查询语言.在多数OLAPServer都提供Mdx支持,如Microsoft Sql Server ...

  3. C#调用系统API

    API简介 1) C#中的简单数据类型与API中的数据类型对应关系 2) 如何在调用API时传递复杂参数:封装类.结构和联合 3) 如何调用API 4) 如何确保成功调用API

  4. mysql --mysqli::multi_query 和 mysqli_multi_query

    语法: 对象化:bool mysqli::multi_query ( string $query ) 过程化:bool mysqli_multi_query ( mysqli $link , stri ...

  5. gcc参数PIE和PIC的区别和共同点

    gcc参数的PIE和PIC 区别 PIE:用在可执行文件 PIC:用在库文件 共同点 生成跟位置没有关系的symbol

  6. Linq系列(5)——表达式树之案例应用

    在进入今天的正题之前,先感慨下本人的blog的人气一篇不如一篇.再加上换公司后人身自由受到了比之前大得多得多的限制,实在令本人有些郁闷.不过每次提笔写些东西跟大家分享,总是能让我感到愉悦和欣慰,希望我 ...

  7. CENTOS --5分钟搞定Nginx安装的教程

    1. 安装gcc(centos 7之后一般已自带,可以在第6步失败后再安装) yum install gcc gcc-c++ 2. 安装pcre yum install -y pcre pcre-de ...

  8. 链接href的多重使用

    1. 拨打电话 在电话号码前面可以加上 + (加号)表示国际号码. <a href="tel:10086">10086</a> 使用wtai协议进行拨打电话 ...

  9. dubbo项目实战代码展示

    最近公司项目使用dubbo服务,于是就去网上搜索关于dubbo的相关资料,真的很多,但是对于很多人并不是很了解框架或者 不是太适合新手的片段代码,于是我就根据项目的相关内容把dubbo部分单独切出来, ...

  10. 用Dialog 做自定义动画,加播放监听

    final Dialog customDialog = new Dialog(this); customDialog.setTitle(R.string.attention); customDialo ...