简体   繁体   中英

How to add an old .git repository to a project as an old branch

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM