git 如何使用 tortoisegit 执行变基(壁球)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12528854/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to perform rebase (squash) using tortoisegit
提问by zerkms
Cannot get how to perform squash rebase for the current branch. The console command would be
无法获得如何为当前分支执行壁球变基。控制台命令将是
git rebase -i HEAD~2
and then squash as usually. But how to do the same in TGit?
然后像往常一样挤压。但是如何在 TGit 中做同样的事情呢?
Script to initialize the case
用于初始化案例的脚本
git init .
touch 1
git add 1
git commit -m "1"
touch 2
git add 2
git commit -m "2"
touch 3
git add 3
git commit -m "3"
As a result after squashing we would have 1 commit with 3 files.
因此,在压缩之后,我们将有 3 个文件的 1 次提交。
Any proposals?
有什么建议吗?
回答by sschuberth
This works for me using TortoiseGit 1.7.12:
这对我使用 TortoiseGit 1.7.12 有效:
- Right-click on the working directory where you want to do an interactive rebase and choose
TortoiseGit
->Show log
from the context menu. - In the appearing "Log Messages" dialog, right-click on the most recent commit that you would notlike to rebase anymore and choose
Rebase master onto this...
from the context menu. - In the appearing "Rebase" dialog, tick the
Force Rebase
checkbox and then right-click on the commit to choose betweenPick
,Squash
, etc., or tick theSquash ALL
checkbox in your case. - Press the
Start Rebase
button, which on success turns into aCommit
button, and then into aDone
button. Press all of them.
- 右键单击要执行交互式变基的工作目录,然后从上下文菜单中选择
TortoiseGit
->Show log
。 - 在出现的“日志消息”对话框中,右键单击您不想再重新设置基准的最新提交,然后
Rebase master onto this...
从上下文菜单中进行选择。 - 在出现的“再次基于”对话框中,勾选
Force Rebase
复选框,然后单击鼠标右键的承诺之间做出选择Pick
,Squash
等等,或勾选Squash ALL
复选框,在您的案件。 - 按下
Start Rebase
按钮,成功后变成Commit
按钮,然后变成Done
按钮。按所有这些。
Note that in your example script you would squash / fixup to the root commit, which is a special caseand does not work as described above because the root commit has no parent that you could select in step 2.
请注意,在您的示例脚本中,您将压缩 / 修复到根提交,这是一种特殊情况,不会按上述方式工作,因为根提交没有您可以在步骤 2 中选择的父提交。
回答by regisbsb
You can combine two adjacent commits using the GUI as follows. Remember not do combine commits already on the shared repository.
See:
您可以使用 GUI 组合两个相邻的提交,如下所示。请记住不要合并共享存储库中已有的提交。看:
回答by BuvinJ
Here's what I did using Tortoise Git & storing the repo on Assembla (which is apparently via similar to GitHub).
这是我使用 Tortoise Git 所做的并将 repo 存储在 Assembla 上(显然通过类似于 GitHub)。
I decided I wanted to effectively delete my entire commit history, and start the repo over from scratch. I could have deleted the local git folder and the corresponding repo in Assembla, and then recreated it, but thought it was better to figure out how to do this the “right way”.
我决定要有效地删除我的整个提交历史记录,并从头开始重新存储。我本可以删除本地 git 文件夹和 Assembla 中的相应存储库,然后重新创建它,但认为最好弄清楚如何以“正确的方式”执行此操作。
So, here's how I achieved it:
所以,这是我实现它的方式:
1) Using Tortoise Git, display the repo's log. Highlight all the commits, right click on them, and select “combine into one commit”.
1) 使用 Tortoise Git,显示 repo 的日志。突出显示所有提交,右键单击它们,然后选择“合并为一个提交”。
2) In the dialog that pops up, delete the commit comment (which becomes a combination of all the prior comments), and replace it with a single comment e.g. REBASE. Then initiate the commit. The local repo will then be effectively started from scratch (with all the files still added to it of course) without having to delete and recreate it.
2) 在弹出的对话框中,删除提交注释(它成为所有先前注释的组合),并将其替换为单个注释,例如 REBASE。然后启动提交。然后本地存储库将从头开始有效地启动(当然所有文件仍然添加到其中)而无需删除和重新创建它。
3) Unfortunately, you can't just push it to Assembla. It will reject this, insisting that your “head” is behind the remote branch. So, to solve that first go to the “Settings” page for the repo in Assembla. Enable “Allow –force push”.
3) 不幸的是,您不能将其推送到 Assembla。它会拒绝这一点,坚持认为你的“头”在远程分支的后面。因此,要解决该问题,请首先转到 Assembla 中存储库的“设置”页面。启用“允许 – 强制推送”。
4) Now perform a “forced push”. I don't know if Tortoise Git has a gui option for this, but it is easy to do via the command prompt:
4) 现在执行“强制推送”。我不知道 Tortoise Git 是否有一个 gui 选项,但是通过命令提示符很容易做到:
cd [your repo folder]
git push -f origin
Done!
完毕!
UPDATE:
更新:
To "force push" with TortoiseGit, in the push dialog there are checkboxes to force "known changes" and "unknown changes". I'm not sure what the difference is, but they both result in using the git --force switch. Try "known changes" to begin with.
要使用 TortoiseGit“强制推送”,在推送对话框中有用于强制“已知更改”和“未知更改”的复选框。我不确定有什么区别,但它们都导致使用 git --force 开关。首先尝试“已知更改”。
回答by armin.miedl
- Go to
Show Log
, then make a tag at your current commit (e.g. "tmp"). - Reset hard to the first commit back in history you don't want to change.
- Toggle
All Branches
at the bottom of the log, if you don't see all commits. - Then select all newer commits and make a right click on them:
Cherry Pick selected commits...
- Now you are in interactive rebase mode. There you can do what is common for interactive rebase.
- 转到
Show Log
,然后在您当前的提交中创建一个标记(例如“tmp”)。 - 硬重置为您不想更改的历史记录中的第一次提交。
All Branches
如果没有看到所有提交,请在日志底部切换。- 然后选择所有较新的提交并右键单击它们:
Cherry Pick selected commits...
- 现在您处于交互式 rebase 模式。在那里您可以执行交互式 rebase 的常见操作。
回答by Sven
One way is: Go to log dialog and select "rebase onto *" and then check the "Force" checkbox and mark the commits for "squash" (e.g. by typing 'q').
一种方法是:转到日志对话框并选择“rebase on *”,然后选中“Force”复选框并将提交标记为“squash”(例如,通过键入“q”)。