Git GUI + GitHub,修改最后一次提交有问题,如何快速解决?
Git GUI + GitHub, amend last commit is problematic, how to quickly overcome it?
问题出在 git gui
VERSUS github 上(当我尝试推送使用 git gui
创建的修改提交时)。
很多时候,我没有立即推送,而是编写了更多代码。
当我使用 git gui
提交和推送时,有时我 select "amend last commit" 只是为了重用 git gui
处的提交消息。
当我记得这个交互(git gui
vs GitHub)会把事情搞砸时,我复制了 "ammend last commit" 选项的评论,然后 select "new commit" 再次返回,并在其上粘贴评论。
但是现在我忘记了,我又陷入了这样的混乱之中…… GitHub 不允许我推送修改后的提交,它希望我不必要地合并东西(因为修改后的提交应该起作用,但根本不起作用) .
所以现在,我的源文件乱七八糟(需要合并,合并标签到处都是阻止编译),大约有 20 个文件乱七八糟...
我没有以前的备份。
所以我可以通过某种方式痛苦地获得我以前的提交(使用一些 git 命令行)......但我想有一些直接的方法来覆盖修改过的文件以允许手动合并我最新的适当更改。
我是唯一一个提交文件的人,所以这肯定是 git gui
与 GitHub 错误或限制。
总结:
1) 提交、提交、提交...
2) 修改上次提交(可能会或不会导致问题)
3)做git pull
(它可能会创建合并标签弄乱文件,无法编译,需要针头冲突解决)
来自@VonC 的回答git log --graph --oneline --decorate --all
,叉子看起来很清楚:
* d8f3505 (HEAD, master) improving savable helper
| * 772a6c0 (origin/master, origin/HEAD) improving savable helper
|/
* 15630f3 improving savable helper
或
* fdc9ae1 (HEAD, master) improving savable helper
| * 772a6c0 (origin/master, origin/HEAD) improving savable helper
|/
* 15630f3 improving savable helper
所以,我最近的更改是在 d8f3505 或 fdc9ae1(我恢复了备份以重试,这就是为什么这些数字发生变化的原因)。
此命令保留合并标签,因此不可编译:git reset origin/master
这个命令git reset --hard HEAD@{1}
恢复了772a6c0的修改,所以我丢失了最新的(我还有备份)。
那么,如何制作最新的(d8f3505 或 fdc9ae1 或我再次恢复备份后的另一个新的),成为 win/overwrite HEAD 的那个?
编辑:
使用 git reset --hard 12eb50c
(新 ID)让我在没有合并标签的情况下恢复最新的更改,太棒了!
但是现在,在 git rebase origin/master
之后(这再次弄乱了文件,但现在我有时间备份文件,在非测试用例情况下......),我从 git gui
:
在我接受之后,来自 git gui
的推送停止工作,但是命令行 git push
给我这个消息:
To https://USER@github.com/USER/PROJECT.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://USER@github.com/USER/PROJECT.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. If you did not intend to push that branch, you may want to
hint: specify branches to push or set the 'push.default' configuration variable
hint: to 'simple', 'current' or 'upstream' to push only the current branch.
即使在 git reset --hard 15630f3
之后也无法推送...如果我可以修剪它后面的任何内容并用我的备份源覆盖...
通过选择修改上次提交,您实际上重写了 HEAD 而不是创建新提交(这将毫无问题地推送到 GitHub)
--o--o (origin/master)
\
-O (HEAD: your amended commit)
由于现在的历史不同,GitHub(或任何远程 Git 存储库)希望您先拉取和合并,然后再推送。
为了解决这个问题,因为 O 中的内容对你有好处,但提交本身却不是,你可以:
将 HEAD 重置为 origin/master
,但保留当前工作树
git reset origin/master
从那里添加并提交:这应该将您的工作添加为新提交。
从那里,您可以毫无问题地推送您的新提交(快进)
或者:
找出您最近的更改是什么:
git log --graph --oneline --decorate --all
(它将是最上面的,而不是分叉的)
然后执行此操作,例如:reset --hard fdc9ae1
并备份您恢复的上次源更改。
然后 git checkout master
和 git reset --hard HEAD@{1}
在git push
之前需要git pull
,这样做,合并标签会再次出现...
替换为您的备份,现在您可以再次正常推送了。
注意:使用 git gui 快速 "Amend the last commit"(Git 2.24,2019 年第 4 季度):
使用键盘快捷键“Ctrl+e”打开和关闭修改。
见commit ec7424e (14 Sep 2019) by Birger Skogeng Pedersen (``)。
参见 commit ba41b5b (13 Sep 2019) by Bert Wesarg (bertwesarg
)。
(由 Junio C Hamano -- gitster
-- in commit 7e1976e 合并,2019 年 9 月 18 日)
问题出在 git gui
VERSUS github 上(当我尝试推送使用 git gui
创建的修改提交时)。
很多时候,我没有立即推送,而是编写了更多代码。
当我使用 git gui
提交和推送时,有时我 select "amend last commit" 只是为了重用 git gui
处的提交消息。
当我记得这个交互(git gui
vs GitHub)会把事情搞砸时,我复制了 "ammend last commit" 选项的评论,然后 select "new commit" 再次返回,并在其上粘贴评论。
但是现在我忘记了,我又陷入了这样的混乱之中…… GitHub 不允许我推送修改后的提交,它希望我不必要地合并东西(因为修改后的提交应该起作用,但根本不起作用) .
所以现在,我的源文件乱七八糟(需要合并,合并标签到处都是阻止编译),大约有 20 个文件乱七八糟...
我没有以前的备份。
所以我可以通过某种方式痛苦地获得我以前的提交(使用一些 git 命令行)......但我想有一些直接的方法来覆盖修改过的文件以允许手动合并我最新的适当更改。
我是唯一一个提交文件的人,所以这肯定是 git gui
与 GitHub 错误或限制。
总结:
1) 提交、提交、提交...
2) 修改上次提交(可能会或不会导致问题)
3)做git pull
(它可能会创建合并标签弄乱文件,无法编译,需要针头冲突解决)
来自@VonC 的回答git log --graph --oneline --decorate --all
,叉子看起来很清楚:
* d8f3505 (HEAD, master) improving savable helper
| * 772a6c0 (origin/master, origin/HEAD) improving savable helper
|/
* 15630f3 improving savable helper
或
* fdc9ae1 (HEAD, master) improving savable helper
| * 772a6c0 (origin/master, origin/HEAD) improving savable helper
|/
* 15630f3 improving savable helper
所以,我最近的更改是在 d8f3505 或 fdc9ae1(我恢复了备份以重试,这就是为什么这些数字发生变化的原因)。
此命令保留合并标签,因此不可编译:git reset origin/master
这个命令git reset --hard HEAD@{1}
恢复了772a6c0的修改,所以我丢失了最新的(我还有备份)。
那么,如何制作最新的(d8f3505 或 fdc9ae1 或我再次恢复备份后的另一个新的),成为 win/overwrite HEAD 的那个?
编辑:
使用 git reset --hard 12eb50c
(新 ID)让我在没有合并标签的情况下恢复最新的更改,太棒了!
但是现在,在 git rebase origin/master
之后(这再次弄乱了文件,但现在我有时间备份文件,在非测试用例情况下......),我从 git gui
:
在我接受之后,来自 git gui
的推送停止工作,但是命令行 git push
给我这个消息:
To https://USER@github.com/USER/PROJECT.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://USER@github.com/USER/PROJECT.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. If you did not intend to push that branch, you may want to
hint: specify branches to push or set the 'push.default' configuration variable
hint: to 'simple', 'current' or 'upstream' to push only the current branch.
即使在 git reset --hard 15630f3
之后也无法推送...如果我可以修剪它后面的任何内容并用我的备份源覆盖...
通过选择修改上次提交,您实际上重写了 HEAD 而不是创建新提交(这将毫无问题地推送到 GitHub)
--o--o (origin/master)
\
-O (HEAD: your amended commit)
由于现在的历史不同,GitHub(或任何远程 Git 存储库)希望您先拉取和合并,然后再推送。
为了解决这个问题,因为 O 中的内容对你有好处,但提交本身却不是,你可以:
将 HEAD 重置为
origin/master
,但保留当前工作树git reset origin/master
从那里添加并提交:这应该将您的工作添加为新提交。
从那里,您可以毫无问题地推送您的新提交(快进)
或者:
找出您最近的更改是什么:
git log --graph --oneline --decorate --all
(它将是最上面的,而不是分叉的)
然后执行此操作,例如:reset --hard fdc9ae1
并备份您恢复的上次源更改。
然后 git checkout master
和 git reset --hard HEAD@{1}
在git push
之前需要git pull
,这样做,合并标签会再次出现...
替换为您的备份,现在您可以再次正常推送了。
注意:使用 git gui 快速 "Amend the last commit"(Git 2.24,2019 年第 4 季度):
使用键盘快捷键“Ctrl+e”打开和关闭修改。
见commit ec7424e (14 Sep 2019) by Birger Skogeng Pedersen (``)。
参见 commit ba41b5b (13 Sep 2019) by Bert Wesarg (bertwesarg
)。
(由 Junio C Hamano -- gitster
-- in commit 7e1976e 合并,2019 年 9 月 18 日)