3

How can a directory be copied from a git branch to another without git tracking the files?

My goal is to have different branches for a project and be able to import part of each branch to a single directory for packaging ? Each branch contains code for a specific version of Python, but the package must contain the code for all the Python versions, so the code from all version-specific branches must be copied into the master branch before packaging.

Here is an example:

  • The git-controlled, master-branch directory contains:

    uncertainties/
    
  • I want to import the version of uncertainties/ contained in the python-pre-2.5 branch, so that the final directories are:

    uncertainties/  # Should not be touched
    uncertainties-py23/  # Imported from the python-pre-2.5 branch
    
  • A crucial point is that I do not want git status to report any change (if there was no change in the first place). In other words, the directory import process should be invisible to git.

By using git checkout python-pre-2.5 -- uncertainties and various combinations of renames (mv and git mv), I did not succeed in satisfying this last "git transparency" requirement. How can this be achieved?

Eric O. Lebigot
  • 91,433
  • 48
  • 218
  • 260

2 Answers2

2

Just put uncertainties-py23/ in .gitignore.

Robin Green
  • 32,079
  • 16
  • 104
  • 187
  • Thanks! This almost works: `git status` reports changed files. However, `git commit -a` does not find any file to be committed anything. How can I have `git status` not report changed files? – Eric O. Lebigot Apr 25 '11 at 15:38
  • The files from `uncertainties/` are marked as being modified and staged for commit, but git refers to their imported `python-pre-2.5` version; at the same time, `git status` also reports the modification of the original (master branch) files, with unstaged changes. `git diff` reports changes (and `git commit -a` does not want to commit anything!). – Eric O. Lebigot Apr 25 '11 at 17:09
  • Ah, I think the problem is that `git checkout` makes git think it is on that branch now. See http://stackoverflow.com/questions/160608/how-to-do-a-git-export-like-svn-export – Robin Green Apr 25 '11 at 19:07
1

From master,

git archive python-pre-2.5 uncertanties > uncertanties-py23.tar
mkdir uncertainties-py23
tar xf uncertanties-py23.tar --strip-components=1 -C uncertanties-py23

And then add uncertanties-*/ or similar to your .gitignore.

raylu
  • 2,630
  • 3
  • 17
  • 23
  • The `git archive` command is good to know: thanks! I actually did `tar -C /tmp -xf uncertainties-py23.tar; mv /tmp/uncertainties uncertainties-py23` (no `mkdir` or `--strip-components=1` necessary). – Eric O. Lebigot Apr 26 '11 at 08:30
  • PS: `git archive --output uncertainties-py23.tar …` is also an alternative that does not depend on how the shell handles file clobbering (`>` in sh, `>!` is zsh,…). – Eric O. Lebigot Apr 26 '11 at 08:47