我在git中提交了一定数量的文件,例如:
提交1包含:
- file1
- file2[重命名]
- file3
- file4
现在我想将file2[重命名]文件移动到不同的提交中,而不会影响其他文件。这在git中是否可行?
我在git中提交了一定数量的文件,例如:
提交1包含:
现在我想将file2[重命名]文件移动到不同的提交中,而不会影响其他文件。这在git中是否可行?
初始化代码库
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 reset --soft HEAD~
jeff tg (master +) $ git reset -- file2a
Unstaged changes after reset:
D file2a
jeff tg (master *+) $ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: file1
new file: file2
modified: file3
modified: file4
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: file2a
jeff tg (master *+) $ git reset -- file2
Unstaged changes after reset:
D file2a
jeff tg (master *+) $ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: file1
modified: file3
modified: file4
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: file2a
Untracked files:
(use "git add <file>..." to include in what will be committed)
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%)
git reset --hard HEAD
,然后分别对file1、file3和file4进行更改后再使用git add
。
file2
和file2[renamed]
进行重置。 - Jeff Puckett