将单个文件移出git提交,并将其放在单独的git提交中

将单个文件移出git提交,并将其放在单独的git提交中,git,Git,我在git中提交了一定数量的文件,例如 提交1包含: 文件1 文件2[已重命名] 文件3 文件4 现在,我想将file2[重命名]文件移动到不同的提交中,而不干扰其他文件。在git中可能吗?如果提交1是最后一次提交,请尝试使用git重置-硬头然后git分别添加文件1、文件3和文件4的更改 使用软标志重置以保持阶段性更改 分别重置重命名的文件 作出新的承诺 初始化存储库 jeff ~ $ mkdir tg jeff ~ $ cd tg jeff tg $ git init Initializ

我在git中提交了一定数量的文件,例如

提交1包含:

  • 文件1
  • 文件2[已重命名]
  • 文件3
  • 文件4

现在,我想将file2[重命名]文件移动到不同的提交中,而不干扰其他文件。在git中可能吗?

如果提交1是最后一次提交,请尝试使用git重置-硬头
然后
git分别添加文件1、文件3和文件4的更改

  • 使用软标志重置以保持阶段性更改
  • 分别重置重命名的文件
  • 作出新的承诺

  • 初始化存储库

    jeff ~ $ mkdir tg
    jeff ~ $ cd tg
    jeff tg $ git init
    Initialized empty Git repository in /home/administrator/tg/.git/
    jeff tg (master #) $ touch file1
    jeff tg (master #) $ touch file2a
    jeff tg (master #) $ touch file3
    jeff tg (master #) $ touch file4
    jeff tg (master #) $ git add .
    jeff tg (master #) $ git commit -m "init"
    [master (root-commit) c4668aa] init
     4 files changed, 0 insertions(+), 0 deletions(-)
     create mode 100644 file1
     create mode 100644 file2a
     create mode 100644 file3
     create mode 100644 file4
    
    进行更改并提交1

    jeff tg (master) $ mv file2a file2
    jeff tg (master *) $ echo amendment >> file1
    jeff tg (master *) $ echo amendment >> file3
    jeff tg (master *) $ echo amendment >> file4
    jeff tg (master *) $ git add .
    jeff tg (master +) $ git status 
    On branch master
    Changes to be committed:
      (use "git reset HEAD <file>..." to unstage)
    
            modified:   file1
            renamed:    file2a -> file2
            modified:   file3
            modified:   file4
    
    jeff tg (master +) $ git commit -m "commit 1"
    [master b84034a] commit 1
     4 files changed, 3 insertions(+)
     rename file2a => file2 (100%)
    
    现在添加并提交重命名的文件

    jeff tg (master *) $ git add .
    jeff tg (master +) $ git status 
    On branch master
    Changes to be committed:
      (use "git reset HEAD <file>..." to unstage)
    
            renamed:    file2a -> file2
    
    jeff tg (master +) $ git commit -m "commit 3"
    [master e2fd651] commit 3
     1 file changed, 0 insertions(+), 0 deletions(-)
     rename file2a => file2 (100%)
    
    jeff tg(master*)$git add。
    jeff tg(硕士+$git)状态
    论分行行长
    要提交的更改:
    (使用“git重置磁头…”取消分级)
    重命名:file2a->file2
    jeff tg(主机+$git提交-m“提交3”
    [master e2fd651]提交3
    1个文件已更改,0个插入(+),0个删除(-)
    重命名file2a=>file2(100%)
    
    提交1是否为提交头?是。。即使这样,也没有合并。在合并之前,我想把它分成两个可能的副本。特别是,它很好地演示了您想要的内容,但是您需要为
    file2
    file2[重命名]
    jeff tg (master *+) $ git commit -m "commit 2"
    [master 2f29079] commit 2
     3 files changed, 3 insertions(+)
    
    jeff tg (master *) $ git add .
    jeff tg (master +) $ git status 
    On branch master
    Changes to be committed:
      (use "git reset HEAD <file>..." to unstage)
    
            renamed:    file2a -> file2
    
    jeff tg (master +) $ git commit -m "commit 3"
    [master e2fd651] commit 3
     1 file changed, 0 insertions(+), 0 deletions(-)
     rename file2a => file2 (100%)