TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: Is it me or Git rebase is kind of hard to understand?

6 点作者 Akcium超过 2 年前
I always struggle with the rebase command.<p>git merge is totally find, while git rebase is something mysterious for me.<p>Right now, after yesterday&#x27;s typical work I checked git status and found out that I&#x27;m in the process of rebasing. I used git rebase --abort and lost my changes.<p>Is it lack of discipline to learn this, or it&#x27;s indeed more complicated than merge?<p><i>venting ended</i>

8 条评论

seba_dos1超过 2 年前
It&#x27;s not. Just spend some time thinking about it not as a command to execute, but rather as an operation on a data structure you&#x27;re working with (which is your repository) and it will click.
评论 #34024133 未加载
mikewarot超过 2 年前
Git <i>appears</i> to be a tool to manage merges using deltas. Git is <i>actually</i> a tool that simply stores everything in the current commit, and makes a nice graph showing <i>Connections</i> between those commits which theoretically represent deltas.<p>All trouble arises when this abstraction breaks. It seems to me that the purpose of <i>git merge</i> is to simply allow you to work around broken abstractions. You can make the graph appear how you want, without having to jump through a bazillion unnecessary hoops to make a nice set of deltas.<p>Or... I&#x27;m wrong and about to find out after hitting &quot;add comment&quot;
savg超过 2 年前
I&#x27;m the opposite and think rebasing is easier, but I am biased obviously since I have only used rebasing to solve merge conflicts.<p>There are a couple ways of performing a git rebase, namely<p>* git rebase<p>* git rebase interactive (git rebase -i)<p>* git rebase --onto<p>I think following these videos may help and will explain it better than I can.<p>What is Git Rebase? [Intermediate Git Tutorial] - <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=_UZEXUrj-Ds">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=_UZEXUrj-Ds</a><p>Squashing Git commits with Interactive Rebase -<a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=7IfkL8swmFw">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=7IfkL8swmFw</a><p>How to undo git rebase using git reflog. - <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=qP4i3S2hujc&amp;t=203s">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=qP4i3S2hujc&amp;t=203s</a>
评论 #34014946 未加载
dyingkneepad超过 2 年前
Everything Git is kind of hard to understand, but once it &quot;clicks&quot;, you kinda start thinking it was easy all along.<p>My suggestion is: before every rebase:<p>- mkdir patches<p>- cd patches<p>- git format-patch HEAD~30 (in case you had 30 commits on top of the main branch but you can also &quot;git format-patch $SHA&quot; to get patches up to that SHA, not including)<p>- git pull --rebase<p>Then, if the rebase fails:<p>- git checkout -b branchname-rebaseattempt origin&#x2F;branch<p>- make<p>- git am 0001*<p>- make<p>- git am 0002*<p>- git am --abort<p>- etc<p>This way you have a backup copy of every one of your commits as a patch file, and you can better understand and fix your conflict step-by-step without being &quot;locked&quot; in the process of a git-rebase. Sometimes when there are simple conflicts I edit the patch files themselves before applying.
评论 #34024147 未加载
Jimostar超过 2 年前
Hello everyone, I have some wise advice that will help you if you want to unwind and have a nice time. For instance, <a href="https:&#x2F;&#x2F;grantubodesexo.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;grantubodesexo.com&#x2F;</a> is perfect for a night out because it allows you to let off steam while having fun. I think you should have a look.
mindcrash超过 2 年前
&quot;Within a converged timeline there are two timelines of events, so to create a new non-converged timeline you have to go back to the point in time where those timelines converged and add every event in the converged timelines in order in the new timeline.<p>If things don&#x27;t really work and a conflict emerges you, as the master of time, have to decide the right data to put into the new timeline&quot;<p>Hope it helps you breathe more easily :)
Am4TIfIsER0ppos超过 2 年前
How the hell is it mysterious? It is just cherry-picking the commits then setting the branch pointer. Merge is the evil one because you can hide any changes you like in the commit.
评论 #34024150 未加载
gardenhedge超过 2 年前
Git is a good idea with a poor execution and naming