-2

Consider following directories:

./new
./repo

where ./new only contains textual files and subdirectories that are not under revision control by git, while ./repo comes from git clone git@myhost/repo/ (master)

What I want is to create a new local branch called test of repo/master including the difference between the ./repo directory itself and the new ./new directory.

How can I do this with the minimum number of steps using git and diff eventually?

Martin
  • 9,089
  • 11
  • 52
  • 87
  • 1
    I don't understand what you are trying to achieve. The "new" directory is outside of "repo", what should the difference look like? does "new" contain files that already exist inside "repo"? – coredump Jan 08 '18 at 13:55

1 Answers1

1

If I understand correctly, you wish to create a new branch that contains only the contents of ./new, with the first commit representing the diff between ./repo and ./new.

If that's correct, then I would do the following:

  1. Create the new branch in ./repo (via git checkout -b test).
  2. Delete everything except for .git. (via git rm -r '*').
  3. Copy the content over from the ./new (via cp ../new/. .).
  4. git diff/status etc. will now correspond to the changes.

It's possible there's a way to optimise this workflow (especially step #2), but it doesn't seem particularly onerous for what (I assume) is an infrequent workflow!

Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680
  • I guess it is not what he is looking for, because he said, he wants to have the current changes of the current branch in the new branch. Instead of delete and copy the files I would merge the current branch into the new branch and create the new ./new directory. –  Jan 08 '18 at 14:58
  • 1
    @Philj0 - I'm not sure that's at all clear. The question is what "including the difference between..." is supposed to mean. That might be more clear if we knew more about the files - i.e. if "new" is just a newer version of the project that isn't yet in source control - but in any case it suggests some unclear thinking about whether git commits are snapshots or diffs. In fact they're snapshots, so in most reasonable interpretations what Oliver suggests seems correct. – Mark Adelsberger Jan 08 '18 at 15:56