git-merge with repository on local filesystem

2020-06-11 11:14发布

问题:

For some context: I just upgraded Ubuntu which broke my existing gitosis installation (see here: bug #368895), and have just reinstalled gitosis from packages. I now want to migrate my whole config and set of repositories from the old gitosis installation (which still exists and can be pulled from but is otherwise broken).

I now have two gitosis-admin directories locally, one for each gitosis installation. One has a full history, the other's is empty. I want to pull across this history. Here's what's happening though:

me@server:~/gitosis-admin-new$ git merge ../gitosis-admin-old/
fatal: '../gitosis-admin-old/' does not point to a commit

... where there is are git repositories in ~/gitosis-admin-old/ and ~/gitosis-admin-new/

I'm probably going to need to do this for the other repositories too, which have much longer and more important histories, so copying and committing as one is not an option.

What am I doing wrong? I've tried pointing to .git/HEAD which as I understand is a commit, but that doesn't work. Could someone explain how to do this? Thanks!

回答1:

You need to use git pull with repository, not git merge (which is for branches):

git pull ../gitosis-admin-old/

You might need to select a branch in remote to merge, e.g.:

git pull ../gitosis-admin-old/ master

If you need to do this merge only once, then using git remote add like in jamessan answer is unnecessary work. On the other hand if you would be revisiting the remote (pulling more than one time), this solution would be better than using git pull <location> <branch>.



回答2:

You need to create a remote for that repository and then fetch & merge (or simply pull) from there.

git remote add admin-old file://$HOME/gitosis-admin-old
git pull admin-old