git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Master and origin/master diverged

From
HWHilco Wijbenga <hilco.wijbenga@gmail.com>
Date
Jun 26, 2012, 02:49 UTC
Message-ID
<CAE1pOi24EVq__XzxtBoAryzQ+F=sAy8-hY23M-P4YoQFXdpSSw@mail.gmail.com>
In-Reply-To
<4FE50411.8080800@gmail.com>
On 22 June 2012 16:47, Neal Kreitzinger <nkreitzinger@gmail.com> wrote:
Show 52 quoted lines
> On 6/22/2012 3:18 PM, Hilco Wijbenga wrote:
>>
>>
>> On 22 June 2012 12:01, Neal Kreitzinger <nkreitzinger@gmail.com> wrote:
>>>
>>> On 6/22/2012 12:53 PM, Hilco Wijbenga wrote:
>>>>
>>>>
>>>> One of my developers managed to push something that somehow "diverged"
>>>> origin/master from everyone else's local master.
>>>>
>>>> A --> B --> C --> D (everybody's local master)
>>>> |
>>>> \--> B' --> C' --> D' --> E (origin/master)
>>>>
>>>> (i.e., A is the commit where things diverged; everyone's local master
>>>> points to D but the new commit (E) that was pushed to origin/master
>>>> uses different SHA1s for B, C, and D)...
>>>>
>>>>
>>>> Now running git pull creates a merge commit joining D and E.
>>>>
>>>> ...Does anyone have any idea as to what might have happened? Perhaps if
>>>> I
>>>>
>>>> understand how this happened I might be able to prevent it from
>>>> happening again.
>>>>
>>> Some ways you can prevent it from happening again:
>>
>>
>>> (2) have your devs do git pull --ff-only
>>
>>
>> Is this something that can be set in git config? I looked but didn't
>> see anything obvious.
>
>
> OTTOMH, you could change the git fetch config for master and take away the
> leading '+' sign which would not allow non-fastforward fetches of master.
>  That in turn would prevent merging such a non-ff remote tracking branch of
> master into your branch master.
>
>
> Actually, I guess what I really want is
>>
>> something for git push, right?
>>
> Some ways to do it:
> (1) I think you could have rebase and commit hooks locally that prevent
> someone from rewriting history on master.  That in turn would prevent
> someone from pushing a rewritten history.
Yes, I have been thinking about that.

How does one create "portable" hooks? I have to deal with GNU/Linux, OS X, and MS Windows. We all have Java installed so I first thought of using JGit but I am not clear on how well JGit supports using it in a hooks. Should I make Ruby a required part of the dev environment and use Ruby hooks?

> (2) When merging topic branches to master use git merge --ff-only.  Then
> when you push it to remote master you know it's a fastforward and not a
> history rewrite.

Given how hard it is to teach devs to only push fast-forward merges, I am not sure how well this would work.

Previous: Neal KreitzingerNext: Neal Kreitzinger
Message 9 of 13 in “Master and origin/master diverged”
  1. Hilco WijbengaJun 22, 2012
  2. Phil HordJun 22, 2012
  3. Hilco WijbengaJun 22, 2012
  4. Phil HordJun 22, 2012
  5. Hilco WijbengaJun 22, 2012
  6. Neal KreitzingerJun 22, 2012
  7. Hilco WijbengaJun 22, 2012
  8. Neal KreitzingerJun 22, 2012
  9. Hilco WijbengaJun 26, 2012
  10. Neal KreitzingerJun 27, 2012
  11. Junio C HamanoJun 22, 2012
  12. Hilco WijbengaJun 26, 2012
  13. Junio C HamanoJun 26, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.