重定基址时,为什么';t git add——补丁工作?
在git存储库中,我有一个文件,其中包含一个大提交,我希望将其划分为多个提交。我正试图按照现场的指示操作,但遇到了问题重定基址时,为什么';t git add——补丁工作?,git,git-rebase,git-diff,git-add,Git,Git Rebase,Git Diff,Git Add,在git存储库中,我有一个文件,其中包含一个大提交,我希望将其划分为多个提交。我正试图按照现场的指示操作,但遇到了问题git status显示file.js未被跟踪,但git add-p file.js响应“无更改” 我做了一个简单的解释来确切说明我的意思 在这个特定的存储库中,我想将commit 92cc4839abe2bfe54981d8227c17acf07c24c84b划分为几个commit,每个commit向file.js添加一个函数。然而,我发现的唯一有用的说明失败了 如何复制: g
git status
显示file.js未被跟踪,但git add-p file.js
响应“无更改”
我做了一个简单的解释来确切说明我的意思
在这个特定的存储库中,我想将commit 92cc4839abe2bfe54981d8227c17acf07c24c84b划分为几个commit,每个commit向file.js添加一个函数。然而,我发现的唯一有用的说明失败了
如何复制:
git克隆https://github.com/jgibbons94/rebase-error.git
cd重定基址错误/
git rebase-i HEAD~2
并标记commit 92cc483进行编辑。其他一切保持不变git复位头~
git状态
列出未跟踪的文件.jsgit diff file.js
未显示任何更改git add-p file.js
响应“无更改”92cc483
添加了该文件,因此当您执行git reset
以备份92cc483
的副本时,会从git的索引中删除该文件
提醒:索引或暂存区域(同一事物的两个术语)保存将进入下一次提交的每个文件的副本。它最初是当前提交的副本。因此,git reset HEAD~1
(或任何等效项)意味着取出索引中的所有内容,然后放入HEAD~1
中的所有内容。文件file.js
不在前一次提交中,因此现在也不在索引中
git add-p
命令的索引中需要有要修补的内容。索引中的一个空文件就足够了,并且git add-N
创建了这样一个条目,因此:
git add -N file.js
将允许您运行git add-p file.js
这并不是很有用,因为整个file.js
现在将显示为补丁。您不妨在编辑器中打开file.js
,剪掉大部分内容,写回原处,然后在编辑器仍处于打开状态时运行git add file.js
,然后撤消剪掉的部分,这样您就拥有了全部内容。现在,您在索引中有了您想要的file.js
副本:
$ vi file.js # open file.js in editor
[snip]
:w
^Z # suspend editor - or, open another window to run git add
$ git add file.js
$ fg # resume editor
[undo snippage]
:x # write and exit
所有这些的结果是:
$ git status
interactive rebase in progress; onto 85aa6aa
Last command done (1 command done):
edit 92cc483 A really big commit
Next command to do (1 remaining command):
pick 3891479 Add description.txt
(use "git rebase --edit-todo" to view and edit)
You are currently splitting a commit while rebasing branch 'master' on '85aa6aa'.
(Once your working directory is clean, run "git rebase --continue")
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: file.js
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: file.js
$git状态
正在进行的交互式重新基址;在85aa6aa上
最后一个命令完成(1个命令完成):
编辑92cc483一个非常大的提交
下一个要执行的命令(剩余1个命令):
选择3891479 Add description.txt
(使用“git rebase--编辑todo”查看和编辑)
您当前正在对“85aa6aa”上的分支“master”重定基址时拆分提交。
(一旦您的工作目录是干净的,运行“git-rebase--continue”)
要提交的更改:
(使用“git还原--暂存…”取消暂存)
新文件:file.js
未为提交而暂存的更改:
(使用“git add…”更新将提交的内容)
(使用“git restore…”放弃工作目录中的更改)
修改:file.js
我现在可以git commit
、恢复编辑器、剪贴(这次更少)、写入、挂起、git add
、git commit
、恢复编辑器和撤消剪贴等,直到完成每个函数的所有提交。无需为笨重的git add-p