在不合并的情况下加入各种提交 [英] Joining various commits in one without merging

查看:178
本文介绍了在不合并的情况下加入各种提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我的情况:

OSX 10.6和10.7 so
我已经修复了10.6的一些东西,然后提交,
更改为10.7,并再次修复了这些修复以便它们兼容,然后再次提交。
然后返回到10.6并再次检查并再次做一个小的提交等
(总共提交了三次或四次提交,所有这些提交都是针对同一问题的)

正如你看到所有这些提交密切相关,所以我想加入他们,这可能吗?



我仍然需要工作还有一个问题,所以我不打算合并当前分支。
理想情况下,我希望每个问题只有一个提交/缺陷解决。


$ b

我推送了我的提交,因为我必须在不同的计算机上执行此操作,但该分支未被其他人使用,尚未使用。

解决方案

一个很好的交互方式是使用 git rebase -i 。查看一个分支,查看历史记录,然后在第一次提交之前选择一个您想要加入的提交(称为压缩)。然后

  git rebase -i<提交> 

在编辑器中,您会看到一个提交列表选择了最近的一个。它看起来像

 选择2f4b7fa某些提交消息
选择19f58bd其他提交消息

找到您想要加入的第一个提交。让那一套去挑选。然后,对于所有想要压缩的那些,请将pick改为squash或s。标记提交压扁意味着它将立即与之前(之上)的提交相结合。然后保存并退出。系统会提示您为将要创建的新提交提交新的提交消息。保存并退出,你就完成了。请注意,您也可以使用分层视图来移动周围的提交。所以,如果你有一些失败的提交,或者你需要将提交移动到一起压缩它们,你也可以这样做。另一个注意事项:如果你已经将提交推送到远程,那么这可能会让事情发生变化,特别是如果你正在与从该远程访问的其他人一起工作。



编辑:由于您已经推送了分支,并且您知道没有其他人正在使用它,只需执行上述步骤,然后执行 git push origin master -f ,假设remote repo是origin,并且你在master分支上。这是一个正常的推动,但-f告诉它覆盖遥控器上的任何内容,并强制应用您的更改。这是当你从别人共享的回购工作,这变得危险和/或混乱。


Is it possible to join various commits?

This is my case:

My app runst in OSX 10.6 and 10.7 so I have fixed some stuff for 10.6 then committed, changed to 10.7 and fixed the fixes again so they are compatible, then commit again. then went back to 10.6 and check it again and make a small commit again, etc. (three or four commits in total and all these commits are for the same issue)

As you see all these commits are closely related so I would like to join them, Is this possible?

I still have to work in one more issue so I don't plan to merge the current branch. Ideally I would like to have only one commit per issue/bug I solve.

EDIT:

I have pushed my commits since I have to do this in different computers but the branch is not being used by someone else, not yet.

解决方案

A nice, interactive way is with git rebase -i. Check out a branch, look at the history, and pick a commit that's before the first commit you want to "join" (it's called squashing). Then

git rebase -i <the commit>

In an editor, you'll be shown a list of commits from the one right after the one you chose to the most recent one. It looks like

pick 2f4b7fa Some commit message
pick 19f58bd Some other commit message

Find the first commit in the ones you want to join. Leave that one set to "pick". Then, for all the ones you want to squash into that, change the "pick" to "squash" or just "s". Marking a commit "squash" means that it will be combined with the commit immediately before (above) it. Then save and exit. You'll be prompted for a new commit message for the new commit that will be created. Save that and exit, and you're done. Note that you can also use the rebase view to move commits around by shuffling the lines around. So if you have some commits that are out of order or you need to move commits together to squash them, you can do that, too. Another note: if you've pushed your commits to a remote, this can jack things up, especially if you're working with other people who pull from that remote.

Edit: Since you've pushed the branch already, and you know that nobody else is using it, just follow the above steps, and then do a git push origin master -f, assuming the remote repo is "origin" and you're on the master branch. That's a normal push, but the -f tells it to overwrite whatever is on the remote and force your changes to be applied instead. It's when you're working from a repo shared by others that this becomes dangerous and/or confusing.

这篇关于在不合并的情况下加入各种提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆