这在我身上经常发生:
经过一天的编码后,我开始为某个功能进行相关更改。我主要通过“git add -p”来选择性地只添加相关的更改(保持调试的东西等等)。
但后来我意识到我也做了一些同样值得承诺的事情。它与功能无关,但会影响相同的代码。因此我想在此之前提交。不幸的是,我已经花了很多时间来展示这个功能。你如何处理这种情况?
我目前的解决方案是这样的:
(想象部分功能“B”已经上演,现在你意识到有功能“A”)
cp .git/index .git/index_bak #Save partly staged feature B
git reset #Start again
git add -p #Stage only A
git commit #Commit only A
mv .git/index_bak .git/index #Restore stage. This is now a bit strange
#as it seems to remove feature A. Therefore
#reapply feature A (which is still in the
#working directory) again - only to the stage
git diff -U0 HEAD~1.. | git apply --cached --unidiff-zero
git add -p #Continue stageing B