-1

I have searched but I haven't found the solution. Maybe I wasn't persistent enough in my research. If I've missed something, I'd be grateful if you send some links.

I have worked with some guy on the same project. He has a project folder with git repository on his machine.

I have copied the last version of his working directory but without his .git on my computer one week ago.

I've installed my own git and I've made already several commits (only one master brunch, easy as it is, just to compare and control the changes/versions in Sublime Text). He doesn't work here anymore and he has not committed the changes, but I can do this from his working machine.

The problem is: now I need to add his git to my but as another branch (old-branch).

Therefore two questions:

  1. How can I make a commit on his computer with an old date (one week ago).
  2. How can I add this commit/commits/all data in his .git repository to my .git repository but as another branch, an old one.

A precision: these two folders on his computer and mine are absolutely the same, I just want to add all his changes to my git (not only the last commit I make, but old commits he made before also), but not to mix them with my changes I've made. I suppose to add this as an old-branch etc. But maybe you know a better solution.

Thank you in advance for your help!

Daemon Painter
  • 3,208
  • 3
  • 29
  • 44
  • Does this answer your question? [How to import existing Git repository into another?](https://stackoverflow.com/questions/1683531/how-to-import-existing-git-repository-into-another) – Joe Jul 24 '20 at 13:03
  • Well, it sounds similar, but I don't need to add an old directory, cause all the files are the same, it's just two copies of the same project. I need just to merge old .git changes with the new ones. and to differentiate them (with brunches for example). But I should be able to see the difference between the old branch and my current branch with the same facility as I compare the difference between different versions in my current brunch... Is it possible? – GZstudio GZstudio Jul 24 '20 at 13:13
  • Maybe you're even right and it can solve my problem, but I am not very familiar with git (3 weeks of experience in total)))) . How exactly should I implement this solution?? I think git-subtree is a thing I need, but I'm not sure. It's not the same as brunches, isn't it? Which option suites better for my needs?? – GZstudio GZstudio Jul 24 '20 at 13:22
  • Please review this - it contains few git command to add new origin and submit code from one repository to another one. https://stackoverflow.com/questions/34384642/how-to-copy-a-branch-from-one-github-repository-to-another – mybrave Jul 24 '20 at 13:38

1 Answers1

0

I may be mistaken, but you can't do what you want. Here is some nice question and answer explaining why.

The commits you created on your master branch, going back to the first ever one, are determined with a parent. You want to add a parent to the first you ever made, and that would be the last commit from the "real" repository or something. You won't be able to do it, not without destroying your local commits.

Instead, walk another way.

Commit everything from your colleague working machine, then git clone that repository from either a blessed remote or its machine directly.

Now, git add remote <your local wd> wd to add your local working directory as a secondary remote to that repo you just cloned.

Then, in the clone, git checkout -b integrationBranch and git pull wd/master. Then git merge.

In this way, you'll pile your commits on top of those of the old repository. You are not adding old history to new, but rather new history on old, which is much much better.

EDIT: a note on time

A commit records its creation date and author, besides its parents and children. Moving stacks of commits around doesn't modify the creation date. Meaning, if you git pull today a stack of commits made 2 years ago, you'll still see that they were created 2 years ago.

Daemon Painter
  • 3,208
  • 3
  • 29
  • 44
  • Well, maybe not exactly... I don't want to change the existing commits. And maybe, even the time is not important. I just need to be able to see his worm separately from my. Branches or git-subtree?? What functionality is better for this? And if I make as you've described, how can I delimiter the time when I started to work on this project?? Or just with git-message? – GZstudio GZstudio Jul 24 '20 at 16:47
  • Why is the worm so important? In the end, your worm is branching out from his worm. Seems like you want to rewrite history in your favour. Anyway, you may do the same the other way around. Go commit his stuff, add his repo as secondary remote to yours, pull everything into a branch, remove the secondary remote. Please be careful: Trying to modify the parent of a commit will result in that commit being destroyed and a new one being born. And this is recursive down through your entire history... Which is functionally better, it's opinion based, and not really an answer – Daemon Painter Jul 25 '20 at 10:27