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

Re: two branches: keep one difference but merge others forth and back

From
Carlos Martín Nieto <cmn@elego.de>
Date
Nov 28, 2011, 15:25 UTC
Message-ID
<20111128152536.GB2386@beez.lab.cmartin.tk>
In-Reply-To
<jats5v$r7c$1@dough.gmane.org>
On Sun, Nov 27, 2011 at 06:31:42PM +0100, Gelonida N wrote:
Show 15 quoted lines
> Hi,
> 
> 
> Is this possible.
> 
> 
> I'd like to have two branches.
> 
> If possible I would be able to merge forth and back between both of them.
> 
> However I would like, that certain differences will be kept between both
> branches.
> 
> Is there any way to tell git to permanently ignoring certain commits
> from merging?
This goes against what a merge is.
Show 28 quoted lines
> 
> 
> Example:
> ---------
>    Normally shell scripts would have a first line of
> '#!/bin/bash',
> but in a certain branch I would like that the first lines would be
> 
> '#!/usr/local/bin/bash'
> 
> All from then on however I'd like to be able to commit on both branches
> and to merge from the other branches (and always keep this difference)
> 
> What I tried:
> -------------
> My first naive approach was:
> - create shell scripts in master,
> - create then a branch named 'my_shell'
> - modify first lines of shell scripts in this branch and commit
> - checkout master
> - merge my_shell to master with merge strategy 'ours'
>   git pull my_shell -s ours
> - now I changed something else in master
> - when I try to merge back to branch my_shell I will not only get
>   the most recent changes done in master, but I will also undo the
> changes in line 1 of my shell scripts.
> 
> So it seems I am not doing things as one should.

If you tell git to merge, it expects that you want to take the changes done in the other branch.

Show 13 quoted lines
> 
> 
> Potential other strategies:
> ----------------------------
> - never commit anything on branch my_shell and just pull regularly
>   from master to keep it synced.
> 
> - commit changes / bug fixes also on branch my_shell, but NEVER merge
> back to master. If a change grom my_shell is really needed on master,
> then just cherry-pick.
> 
> 
> Thanks in advance for suggestions how you would deal with such 'situations'

You can amend the merge (or the next merge) commit so you undo that change. Git should leave that line alone as long as you don't change it.

Or you could have a branch where you make changes and two branches where you change the hashbang. Merging from the main branch into the specific branches won't touch the hashbang, as long as you don't touch it.

   cmn
Previous: Gelonida NNext: Tor Arntsen
Message 2 of 3 in “two branches: keep one difference but merge others forth and back”
  1. Gelonida NNov 27, 2011
  2. Carlos Martín NietoNov 28, 2011
  3. Tor ArntsenNov 30, 2011

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.