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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Ask HN: What is your approach to dealing with merge conflicts day in / day out?

1 点作者 jossclimb将近 2 年前
I am working on a project with quite few others (OSS) and constantly hitting merge conflicts, which I then turn into a dumpster fire. Sometimes things go well, other times I just close the PR. Make a fresh branch and start again, as git and GitHub have fallen out.<p>My current approach is:<p>1. Change to main<p>2. `git pull` latest changes<p>3. Change to my feature branch<p>4. git merge origin&#x2F;main<p>5. Get CONFLICTS<p>6. Fix CONFLICTS<p>7. git add -A<p>8. git commit -m &quot;Rebase from main&quot;<p>9. Fingers crossed, git push origin myfeature<p>I have also tried `git rebase origin&#x2F;main` at #4, but this often pulls everyone elses commits into my change, which gets me complaints during review.<p>At this point it will either go well, or blow up. Sometimes GitHub will claim there is still a merge conflict, even though my local file and the remove file in main are identical. Other times I have new commits locally, I push them upstream and git tells me<p>Is there any idiot proof approach I can take here. I am guessing this is more the tradesmen at fault, more than the tools. So willing to look a fool here, but this is a bit of a PIA right now.

1 comment

xnorswap将近 2 年前
If merge conflicts are that common, either you&#x27;re all tripping over each other trying to do things in different ways, or they are &quot;artificial&quot; conflicts caused by people rebasing public shared &#x2F; branches.<p>Merge conflicts should be occasional, not an everyday occurrence.<p>Atlassian&#x27;s golden rule: Never rebase a public branch.<p>Try to understand where conflicts are coming from. Are people committing different linting&#x2F;whitespace&#x2F;line-endings.<p>If so, then get automated tooling on the repo which enforces a linting and style guide to prevent re-format conflicts.<p>If they&#x27;re from genuine refactors, try to understand why people are refactoring so much in a way that is causing conflicts.