Reputation: 113
I'm fairly new to git and only know the basics. I've tried to find information on this, but maybe I'm just not capable of expressing what I need to do in search terms.
My company hired a 3rd party developer that took code from a known repository and made changes. Unfortunately, they did not document any of their changes with comments. We were given a zip file, with only a rough assumption of what version the code was originally cloned from. However, we need to keep their changes AND update to the latest version on the live repository. What is the best way to handle this with git? The zip file only contains the files from the repo, no git versioning history.
Can someone please offer advice on how to ensure we're using the latest code without losing their changes?
Upvotes: 3
Views: 1334
Reputation: 30297
I don't think the other answers are really tackling the problem from the root: find the revisión where the development of the zip started. Create a branch in that revision and check it out. Then remove everything from your working tree (don't mess with .git directory, just in case), replace the content with the zip, git add everything and create a new revision.... something like git commit -m "the zip"
. Now you can go to whatever branch and merge the branch that you created for this..... or rebase it, whatever you need.
Upvotes: 4
Reputation: 76884
This is totally possible to do.
You can create a branch based off where you think the code started (call it import
). You can unpack the contents into the working tree, overwriting all the files, and commit. Now you can see the diff between the original and the changes using git diff HEAD^
.
When you want to merge these changes, you can then switch to master
, run git merge import
, and resolve any conflicts.
If you think you've made a mistake about where it's based off of, you can create a temporary branch with the current contents (git branch temp import
), check out import
, rebase it onto the new commit (git rebase --onto NEW import^
), and then reset the branch to its original value (git reset --hard temp
). That provides a quick and easy way to find the right parent so that your merge produces the best possible result.
In general, you do want to try to find as closely as possible which commit the original was based off of, because the way a merge works is that it incorporates the changes that have happened on both branches. Knowing which changes those are of course depends on finding the merge base, which in this case is the last commit master
and import
share in common (the fork point).
Upvotes: 2
Reputation: 76968
Yes, of course. Actually this is easier said than done, but once you follow these steps you are guaranteed to succeed. You will not enjoy the process, but you will enjoy the result.
Upvotes: 1