0

I am relatively new to git and I need to do the following.

  1. Given a module, X ,in repo A, i want to move, X, to repo B
  2. I need to do this why while preserving the history of certain authors. i.e preserving the commit history of 'joe' and 'bob' and noting else.

Any ideas on how I can do this?

Thanks!.

1615903
  • 32,635
  • 12
  • 70
  • 99
SFD
  • 565
  • 7
  • 18
  • 1
    Possible duplicate of [git: Apply changes introduced by commit in one repo to another repo](http://stackoverflow.com/questions/3816040/git-apply-changes-introduced-by-commit-in-one-repo-to-another-repo) – jones j alapat Mar 06 '17 at 09:08
  • You don't define "module" here and that will likely be important. Meanwhile, note that in Git, the history *is* the commits. The two are inseparable. Each commit is a snapshot; history is formed by playing the snapshots over time. – torek Mar 06 '17 at 09:40
  • Possible duplicate of [Detach (move) subdirectory into separate Git repository](http://stackoverflow.com/questions/359424/detach-move-subdirectory-into-separate-git-repository) – Joe Mar 06 '17 at 11:41

1 Answers1

1

You could do something like this:

Firstly add 'repo a' locally

git remote add repoa https://github.com/user/repoa.git

Then do a git push to that repo

git push repoa

Likewis eadd 'repo b' locally

git remote add repob https://github.com/user/repob.git

Then do a git push to that repo

git push repob

Doing this will push up the current state of the entire repository.

Now clone the repositories separately:

cd /path/where/you/want/new/repos/to/be
git clone https://github.com/user/repoa.git repoa
git clone https://github.com/user/repob.git repob

(where repoa as the 2nd param is the directory you want to clone into)

and for each run git rm -r with the directories/files you want to remove from that repo, for example for repo-a:

git rm -r src/repob docs/repob

Repeat the above again for repo-b.

Then for each repository run the following command to stage the deletions for commit:

git add -u

Then make a commit as you usually would:

git commit -m "Deleted files from repo b"

Then push

git push origin

Repeat the last 3 commands again for repo-b.

This will create two separate repositories with the complete history of all the files within the repo, unfortunately I don't know a way of retaining the history of 'only the files in that repo'.

Peter Reid
  • 5,139
  • 2
  • 37
  • 33