TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: How often does Git merge make mistakes?

1 pointsby iceman_walmost 10 years ago
I was working on an express app with a friend and git auto merged a file after I ran &#x27;git pull&#x27;. There were no merge conflicts, but git added duplicate functions to a file after merge. I spent an hour trying to figure our what the problem was before realizing that git had made a mistake while merging.<p>I had never seen such a thing before. How often does something like this happen?

1 comment

gknoyalmost 10 years ago
I&#x27;ve never noticed that before, but it&#x27;s possible that you both had added functions in different places:<p><pre><code> foo() ... ; original bar() ... ; added by alice foo() ... foo() ... bar() ... ; added by bob </code></pre> I haven&#x27;t tried it, but I could imagine that being seen as separate text additions, and ending up with duplicates if git thinks it needs to merge them:<p><pre><code> bar() ... ; alice foo() ... ; original bar() ... ; bob </code></pre> You mentioned using `git pull`, which will actually merge things if it thinks it&#x27;s necessary -- which can lead to tree differences. In practice, I&#x27;ve found it helpful to NEVER USE `git pull`. Rather, I advise using:<p><pre><code> git checkout master git fetch origin git merge origin&#x2F;master --ff-only </code></pre> This will ensure that git only does &quot;fast-forward&quot; merges, and does not end up accidentally merging things - and keeps &#x27;origin&#x27; as the system-of-record for what&#x27;s been merged.
评论 #9871277 未加载