问题
Here is the situation: I have inherited two separate machines, one used for "development" the other is the production machine. The problem: They are of course out of sync. In order to bring some sanity to situation I made independent git repositories of the application directory on each machine.
I now wish to be able to compare those repos so I can find out what is different between them. My idea was to make a third repository that contained two branches, one from the repository of the "dev" machine and one from the repository of the "prod" machine.
Is this or an equivalent solution possible with git ?
Thanks.
回答1:
This would use what Git calls "remotes," which are references to what a remote repository contains in order for you to be able to pull it into your own branch, push your branch into the remote repository, etc. You can set up a remote for each of the other machines, and then diff between them to compare them, and you can create one or more local branches from those remotes if you want to do local work.
What I'd suggest for your situation is cloning your development repository, which will create your third repository that you'll be working in, and automatically create a remote named origin
which points to your development repository (this is the conventional name for the default "upstream" place you will be pulling from an pushing to). Then, add a remote for prod
, and now you can compare them and work with them locally. For example:
git clone me@dev-server:/path/to/repo.git
cd repo
git remote add prod me@prod-server:/path/to/repo.git
git remote update
git diff origin/master prod/master
回答2:
The easiest way is to commit all the changes in dev first. Then create a new branch in dev called production with git branch production
and git checkout production
. Then drop all the production files onto dev and overwrite (minus the .git files from production).
Now you have all the changes compared to dev. You can do a git diff and see the changes and git status to see the new files and which files have changed. Commit it and then you can slow do the merge.
I would recommend this method instead of the whole 2 repo thing. Its much easier when your dev and production are in the same repo.
来源:https://stackoverflow.com/questions/4310078/can-a-git-repository-be-created-where-branches-are-clones-from-other-repositorie