Git - 如何使用当前索引(当前状态)的某些非暂时更改来编辑旧(不是以前的)提交? [英] Git - How to edit old (not previous) commit with some of the unstaged changes from current index (current state)?
问题描述
我已经查看了以前的这些问题:
尽管它们并不完全解决特定的问题 - 索引中还有其他更改!当运行 rebase
命令时,git抱怨:无法重新分配:您有未分配的更改。
场景:
最后一个提交之前的提交(我称之为2 HEADs之前?)是一个重构提交。我目前在索引中有许多未分离的更改,但只有其中一些我想添加到之前的最后一次提交中。
我在想象如何做到这一点将是:
-
隐藏
所有当前更改 - 加载(如何?)
- 使用
add -p
和commit - 修改
以选择性地修改这个旧提交 -
rebase --continue
来完成返回到我开始的位置,索引会发生什么变化?) - 然后弹出/清除存储(索引返回到我开始的位置)。
-
-
git rebase -i< ID>
添加到 > parent 之前的最后一次提交,改变索引并移动head -
git stash apply
将存储加载到我的如果您有冲突,git reset HEAD< file>
来卸载文件,则索引不会改变分期。请确保分段已清除。 使用 -
git reset --hard
放弃索引,以便它匹配头 -
git rebase --continue
来完成。更新孩子,将头移回到一开始,但现在将变化
- 历史分为两个版本。另一个分支结束于以前存储在WIP中
- ,然后弹出存储以将索引返回到我开始的位置。另一个分支也被清除。
stash
all of my current changesrebase -i
to the previous to last commit (changing index and moving Head, right?)- load the stash into my index without changing Head (how?)
- use
add -p
andcommit --amend
to selectively modify this old commit rebase --continue
to finish (updates children, moves Head back to where I started, what happens to index?)- then pop/clear the stash (index back to where I started).
git stash
all of my current changesgit rebase -i <ID>
to the parent of the previous to last commit, changing index and moving Headgit stash apply
load the stash into my index without changing Head- if you have conflicts,
git reset HEAD <file>
to unload files staging. Make sure staging is clear.
- if you have conflicts,
- use
add -p
andcommit --amend
to selectively stage changes and commit them git reset --hard
to discard index so it matches Headgit rebase --continue
to finish. updates children, moves Head back to very start, but with changes- history is now forked into two versions. The other branch ends at the WIP previously stashed
- then pop the stash to bring index back to where I started. The other branch is also cleared.
$ li $ code> rebase -i 到上一次提交(改变索引和移动头部,对吗?)
这是正确的吗?如果是,我该如何做第3步?如果不是,我应该怎么做呢?
另外,请注意,我仍然在学习git,但我仍然不能100%确定引用正确使用git(Head,Index,Stash等)的东西。
解决方案:
对于其他人可能会有帮助,这些是我实际采取的步骤:
添加-p
和<$ c $ c $> commit --amend 来选择性地对变化进行阶段化并提交它们
您的计划听起来不错。 git stash apply
或 git stash pop
会修改工作树和/或索引,但不会更改HEAD,所以你应该可以在rebase编辑时做到这一点。
I've taken a look at these previous questions already:
They don't exactly address a particular issue though - there are other changes in the index! When running the rebase
command, git complains: Cannot rebase: You have unstaged changes.
Scenario:
The commit previous to the last one (do I refer to that as "2 HEADs ago"?) was a refactor commit. I currently have in the index many unstaged changes, but only some of which I want to add to the previous to last commit.
I'm imagining the way to do this would be to:
Is this correct? If it is, how do I do step 3? If it isn't, what should I be doing instead?
Also, note that I'm still learning about git and am still not 100% sure I'm referencing things in git (Head, index, stash, etc) properly.
Solution:
For anyone else this may help, these are the steps I actually took:
Your plan sounds good. A git stash apply
or git stash pop
will modify the working tree and/or index, but will not change HEAD, so you should be able to do it while in a rebase edit.
这篇关于Git - 如何使用当前索引(当前状态)的某些非暂时更改来编辑旧(不是以前的)提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!