• git mv与直接mv的区别


    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
     1 file changed, 0 insertions(+), 0 deletions(-)
     rename a => a1 (100%)
    
    $ 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
  • 相关阅读:
    C#产生不重复随机数
    NT6 HDD Installer(硬盘装系统工具)装系统
    R语言实现 广义加性模型 Generalized Additive Models(GAM) 入门
    matlab小段代码学习
    java连接sql server2005
    python正则表达式
    Ubuntu下安装配置JDK 7
    mysql取代rand()的高效率随机读取方法
    UVA 1335 Beijing Guards
    杂思
  • 原文地址:https://www.cnblogs.com/413xiaol/p/10555165.html
Copyright © 2020-2023  润新知