• 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
  • 相关阅读:
    数组越界的现象
    找出数组中的最大值
    Django Form和ModelForm组件
    AJAX
    Mysql数据库概述
    Django中的session和cookie及分页设置
    Django-admin组件使用
    Django中间件
    MySQL视图、触发器、事务、存储过程、函数
    机器学习基础算法__python实现(基于numpy等基础库)
  • 原文地址:https://www.cnblogs.com/413xiaol/p/10555165.html
Copyright © 2020-2023  润新知