git SourceTree 中的壁球

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18348330/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 16:48:19  来源:igfitidea点击:

Squash in SourceTree

gitatlassian-sourcetree

提问by Miles

Is it possible to squash in SourceTree? I saw that apparently you can "drag and drop" commits in order to squash them. However, when I do that it only highlights several commits.

是否可以在 SourceTree 中压扁?我看到显然你可以“拖放”提交以压缩它们。但是,当我这样做时,它只会突出显示几个提交。

采纳答案by Miles

Updated Answer

更新答案

SourceTree for Windows

适用于 Windows 的 SourceTree

As of version 1.5, you can now do interactive rebases, which will allow you to squash.

从版本 1.5 开始,您现在可以进行交互式变基,这将允许您压缩。

SourceTree for Mac

适用于 Mac 的 SourceTree

Interactive rebase has been available in SourceTree for Mac since version 1.6(emphasis mine):

自 1.6 版以来SourceTree for Mac 中已提供交互式变基(重点是我的):

The git rebase –interactivecommand allows you to reorganise your commits after you've created them (but before you've made them public), and now you can do this inside SourceTree. Combine (squash) multiple commits together,or re-order them, simply by dragging & dropping.You can also change the commit message, or edit the content of the commits. Just right-click on a commit in the log and choose ‘Rebase children of <sha>interactively' to kick the process off.

git rebase –interactive命令允许您在创建提交之后(但在将它们公开之前)重新组织提交,现在您可以在 SourceTree 中执行此操作。将多个提交合并(压缩)在一起,或重新排序,只需拖放即可。您还可以更改提交消息,或编辑提交的内容。只需右键单击日志中的提交,然后选择“以<sha>交互方式重新设置子项”以启动该过程。

Old Answer

旧答案

Apparently squashing commits is a feature in SourceTree version 1.6 for the Mac.

显然,压缩提交是适用于 Mac 的 SourceTree 1.6 版中的一项功能。

However, the feature doesn't seem to be available in the Windows version of SourceTree, which is currently still at version 1.0.8.

但是,该功能在 SourceTree 的 Windows 版本中似乎不可用,该版本目前仍为 1.0.8 版本。

Using the command line

使用命令行

You still have the option of using the command line to squash commits:

您仍然可以选择使用命令行来压缩提交:

git rebase -i <sha-of-base-commit>

In the TODOlist, put an s(for squash) next to commits to squash into the previous commit:

TODO列表中,s在提交旁边放置一个(用于壁球)以压缩到上一个提交中:

pick e953225 Add meow meow meow
s def892d Add master

To learn more about how to squash commits using the command line, see Squashing Commits, from the FREEonline Pro Git book.

要了解有关如何使用命令行压缩提交的更多信息,请参阅来自免费在线 Pro Git 书籍的压缩提交

回答by alvarodoune

Right-click on the parent commit and select 'Rebase children of interactively'. After that, you'll be able to drag and drop to squash commits.

右键单击父提交并选择“以交互方式重新设置子项”。之后,您将能够拖放以压缩提交。

回答by snipsnipsnip

As of 1.4.1.0, Windows users still don't have squash. However, you can get the same result by hand.

从 1.4.1.0 开始,Windows 用户仍然没有壁球。但是,您可以手动获得相同的结果。

To squash branch A into branch B:

要将分支 A 压缩到分支 B:

  1. Create a branch from A and call it C.
  2. Reset C to B in softmode.
  3. Check out B.
  4. Commit.

    1.              2.                          3.                             4.
        * <- [A][C]    * <- [A]                    * <- [A]                       * <- [A]
        |              |                           |                              |
        *              * o <- [C] with changes     * o <- [C][B] with changes     * * <- [C][B] committed
        |              |/                          |/                             |/
        * <- [B]       * <- [B]                    *                              *
        |              |                           |                              |
        :              :                           :                              :
    
  1. 从 A 创建一个分支并将其命名为 C。
  2. 模式下将C 重置为 B。
  3. 检查 B。
  4. 犯罪。

    1.              2.                          3.                             4.
        * <- [A][C]    * <- [A]                    * <- [A]                       * <- [A]
        |              |                           |                              |
        *              * o <- [C] with changes     * o <- [C][B] with changes     * * <- [C][B] committed
        |              |/                          |/                             |/
        * <- [B]       * <- [B]                    *                              *
        |              |                           |                              |
        :              :                           :                              :
    

You don't need to create C if you won't need to keep the position of A.

如果您不需要保留 A 的位置,则不需要创建 C。

I recommend opening gitkaside while doing these because you can see all detached commits until you close. (I'd like to see this generosity in SourceTree)

我建议gitk在执行这些操作时将其打开,因为在关闭之前您可以看到所有分离的提交。(我希望在 SourceTree 中看到这种慷慨)

At least, reflog is your friend.

至少,reflog 是你的朋友。

回答by Stef Joosten

Old school Squashing within your own local feature branch

在您自己的本地功能分支中进行旧式挤压

This answer works with most versions of Sourcetree on any platform, because I am using old functionality only. It is quite simple, after you think of it. As usual, it only works before making your work public. I use it to create "tidy" commits in the shared repository, while committing frequently in my own local repository. Assume you are in local branch myfeature. Suppose you are several commits ahead of branch origin/myfeature. You can stay within branch myfeaturethroughout the procedure, so you will not influence anyone else's work.

此答案适用于任何平台上的大多数 Sourcetree 版本,因为我仅使用旧功能。想了想,其实很简单。像往常一样,它仅在您的作品公开之前有效。我使用它在共享存储库中创建“整洁”提交,同时在我自己的本地存储库中频繁提交。假设您在本地分支myfeature。假设您在 branch 之前进行了几次提交origin/myfeature。您可以在myfeature整个过程中留在分支机构,因此您不会影响其他人的工作。

Step 1

第1步

Do a "reset current branch to this commit" on the latest published commit. That is the commit labeled origin/myfeature. A mixed reset will keep all your changes. Be sure to check that your reset is mixed. (If you inadvertedly do a hard reset, you will lose your work...)

在最新发布的提交上执行“将当前分支重置为此提交”。那是标记为 的提交origin/myfeature。混合重置将保留您的所有更改。请务必检查您的重置是否混合。(如果您不小心进行了硬重置,您将丢失您的工作......)

Step 2

第2步

Stage your changes (as usual). Don't forget the files you added or deleted on the way!

分阶段进行更改(像往常一样)。不要忘记您在途中添加或删除的文件!

Step 3

第 3 步

Commit. Write a good commit message that summarizes all of your own (local) commit messages, because they are lost.

犯罪。编写一个好的提交消息,总结您自己的所有(本地)提交消息,因为它们丢失了。

Done!

完毕!

You have squashed everything and cleaned up your local commits in step 1. You are still on your own feature branch, so you haven't influenced anything else. If you feel insecure, label your latest commit before doing anything else. Just for safe keeping. In that way you can always hard-reset to that label in case things go wrong. If everything works out, just remove that label to clean up your commit-history.

您已经在步骤 1 中压缩了所有内容并清理了本地提交。您仍然在自己的功能分支上,因此您没有影响任何其他内容。如果您感到不安全,请在做任何其他事情之前标记您的最新提交。只是为了安全保管。通过这种方式,您可以随时硬重置为该标签,以防出现问题。如果一切顺利,只需删除该标签即可清理您的提交历史记录。

回答by sasikumar

To squash your latest commits ,if you want to last 10 commits

压缩你的最新提交,如果你想持续 10 次提交

1) git reset HEAD~10
2) git add .
3) git commit -am "single commit message for 10 last changes"
4) git push --force

回答by mjlee

They just added the support for "squash" in Windows version as well.

他们也刚刚在 Windows 版本中添加了对“壁球”的支持。

SourceTree version 1.2 for Windows

适用于 Windows 的 SourceTree 1.2 版