Mailing List Archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tlug] Git: bring in a file from another branch

Sometimes to really understand a tool you have to start using it for
real work, and that is where I'm at with git. I'll start a different
thread for one of my questions, which I think is more about ssh. But
before that I'm really struggling doing things that should be simple.

I've these three branches:
   master: git clone of a github repository. (Note, an open source
*library*, not an application.)

   custom: a branch of master, with my bug fixes and new features that
are fed back to the main project.

    myapp: a branch of custom, adding application code that uses this

I naturally do my development on the myapp branch. I've now changed one
of the library files, that I want to feed back to custom. I've already
been burnt by this nieve approach:

   git checkout custom
   git merge myapp

That brings in all my application code. I'd then read I just specify the
particular commit I want. So this time I'd been careful to use two
different commits in myapp, one for library code, one for my application

  $ git merge 160ef92
  Updating e7a7f3f..160ef92
   darren_thoughts.txt                |  124 +++++++++++

Grrr... I.e. it brings in all files from "myapp" [1]. I've searched in
vain for an option to say "just merge this one commit" or "just merge
this one file from that branch", or "just merge with files that already
exist in this branch, and don't create new files".

But it must be possible? If not, how do people develop closed-source
code, using open-source libraries, where they sometimes want to add
features to the libraries?

Just in case you don't understand what I'm trying to do, here is the way
I'll do it if git doesn't support this style of development:
  git checkout myapp
  cd lib
  cp abc{,.new}	#Preserve the file
  git checkout custom
  cd lib
  mv abc
  git commit -m "..." abc
(where the ... will be the commit message I used when I added it to the
myapp branch)

Also, is it possible to veto a directory from being checked out in a
certain branch? I.e. the "custom" branch has the "lib" and "examples"
directories. The "myapp" branch has its own "myapp" directory. I want to
say, under no circumstances, ever [2], should code from the "myapp"
directory end up in the "custom" or "master" branches.

Thanks in advance,


[1]: By the way, to undo the mess the usually all-powerful:
   git reset --hard
is not enough. You have to specify the commit you had before. Luckily
the above merge message gives it. I.e.
   git reset --hard e7a7f3f

[2]: No, really, I mean it :-) The first time this happened to me, git
checkout had brought in the settings file from myapp without my
noticing, and my *passwords* had been pushed to my fork repository on
github. I didn't notice until browsing the files using the github web
interface! I quickly deleted the whole repository on github and started
over fresh :-(.

Darren Cook, Software Researcher/Developer (About me and my work) (My blogs and articles)

Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links