简体   繁体   English

Git-基于一个提交而不解决冲突

[英]Git - rebase to one commit without resolving conflicts

Suppose I've been working on a branch called my-branch , occasionally merging commits from master to stay up-to-date. 假设我一直在一个名为my-branch ,有时会合并master提交以保持最新状态。 On some merges I had to resolve conflicts, which was time consuming. 在某些合并中,我不得不解决冲突,这很耗时。

Now I'm done with my-branch and I want to rebase it to one commit on top of master . 现在, my-branch已经完成, my-branch想将其重新设置为master上的一个提交。 During the rebase I'll have to resolve the same conflicts which is going to be tedious. 在重新设置基准期间,我将不得不解决同样繁琐的冲突。

But I already have the exact state I need the files to be in, I just want to clean up the history. 但是我已经有了需要放入文件的确切状态,我只想清除历史记录。 So the fastest way to rebase would be to: 因此,重新设置基准的最快方法是:

  1. Rewind to master 快退至母带
  2. Make the files the same as in my-branch , but discarding the commit history. 使文件与my-branch的文件相同,但丢弃提交历史记录。 At this point I'd have a lot of uncommited changes. 在这一点上,我将有很多未提交的更改。
  3. Make one commit 提交一次

Is that possible? 那可能吗?

EDIT: SO is telling me to explain why my question isn't a duplicate of this one . 编辑:SO告诉我解释为什么我的问题不是这个问题的重复。 While the most upvoted answer there would solve my problem, the question there is "how to squash commits?" 尽管那里获得最高评价的答案可以解决我的问题,但那里的问题是“如何压缩提交?” and mine is "I know how to squash commits, how to do it without dealing with conflicts?". 我的意思是“我知道如何压缩提交内容,如何在不处理冲突的情况下做到这一点?”。 So the answer is the same, but I didn't find it when looking for the solution before posting here. 所以答案是一样的,但是在这里发布之前寻找解决方案时我找不到它。 Perhaps if someone else also knows about rebase but doesn't know about soft resets, they'll find the solution here. 也许如果其他人也知道变基但不知道软重置,他们会在这里找到解决方案。

Sure.... it's fairly simple using git reset --soft . 当然。...使用git reset --soft非常简单。

git checkout my-branch
git merge master -m "Merging last changes from master"
# we start the magic here
git reset --soft master # set the branch pointer on master
git commit -m "Here's the work for X feature in a single shot"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM