English 中文(简体)
Making cloned repository in git the master
原标题:

I have two git repositories:

  1. report.git (Master on remote location)
  2. cloned.git (Local)

I lost report.git. I have the cloned.git. I want to clone other repositories from this cloned.git. This is possible but my question is am I missing something? Is cloned.git really the same as the master report.git?

cloned.git still points to the Master report.git. I changed this by removing the options in the .git/config. Is this enough?

最佳回答

Your cloned.git repository is a clone (copy) of report.git in the state that report.git was when you cloned or last pulled from report.git

Your cloned.git has always been a master, report.git has always been a master as well. It s the beauty of git.

问题回答
git clone --bare localrepo.git newremoterepo.git

http://git-scm.com/docs/git-clone

Note: Complicated technique desceibed below is required only if cloned repository is working repository (i.e. non-bare repository you commit in, using separate remotes layout), and not bare (or mirror) repository. If cloned.git is a bare repository it is enough to do git clone --bare (or git clone --mirror) to recover original report.git repository (just like e.g. alinrus wrote).


Assuming that you used default configuration and modern Git, which means "separate remotes" layout, you would have remote-tracking branches of report.git in remotes/origin (or remotes/report ) namespace.

To re-create report.git repository you would have to push (or fetch) once from remote-tracking branches to ordinary branches, reverting ordinary fetch refspec (at least for branches: tags are always mirrored). So the refspec for one time push (or fetch) would be something like the following: refs/remotes/origin/*:refs/heads/* plus refs/tags/*:refs/tags/*.


Example recovery session

Let s assume that original report.git repository contains two branches: master and next , and no tags (tags are mapped 1-1, so they shouldn t be a problem, anyway):

$ git init --bare report.git
# ...
[report.git] $ git branch -a
* master
   next

Let s have cloned/.git repository to be oridinary (non-bare and non-mirror) clone of report.git :

$ git clone user@example.com:report.git cloned
Initialized empty Git repository in /tmp/jnareb/cloned/.git/
# ...
[cloned] $ git branch -a
* master
   remotes/origin/HEAD -> origin/master
   remotes/origin/master
   remotes/origin/next
[cloned] $ git remote show origin
* remote origin
  Fetch URL: user@example.com:report.git
  Push  URL: user@example.com:report.git
  HEAD branch: master
  Remote branches:
    master tracked
    next    tracked
  Local branch configured for  git pull :
    master merges with remote master
  Local ref configured for  git push :
    master pushes to master (up to date)

Of course status of your branches, and the number of your local branches might differ for your situation. This is just a simple example.

Now let s remove, or better yet rename (move aside) the original repository report.git , to test our recovery operation

$ mv report.git report-copy.git

Now we recovet the state of report.git that it had on last fetch / pull operation in cloned/.git :

$ git init report.git    # push won t create new repository
# move to  cloned  repository
[cloned] $ git push user@example.com:report.git  refs/remotes/origin/*:refs/heads/* 
Counting objects: 12, done.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (12/12), 839 bytes, done.
Total 12 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (12/12), done.
warning: updating the current branch
# long warning about pushing into current branch
To user@example.com:report.git
 * [new branch]      origin/HEAD -> HEAD
 * [new branch]      origin/master -> master
 * [new branch]      origin/next -> next

Now you can compare report.git and report-copy.git if there are identical. If report.git was non-bare they might differ, because push would not update working directory (and you would need to do git reset --hard HEAD or git checkout in report.git yourself), but it is a bare repository, isn t it?

HTH (hope that helps).





相关问题
git confusion - cloning a repo is returning a past version

Im having some confusion with my git usage. I cloned a repo from one comp to the other, and the new clone is the state of the original that was active some time ago. So its cloning a past version. ...

Appropriate strategy for tagging and hotfixing with git

I was wondering if the strategy I m using for tagging and hotfixing tags (which then I use for deploying rails applications) with git is appropriate. For tagging I just tag a commit of the master ...

Tips on upgrading CVS to git/hg?

We still use CVS, I use git and hg for my personal use though I m still a novice at both, but I realize they re much more modern and better, faster, distributed, etc. It s just everyone is so ...

Using Git in a TFS shop

Using Git at home has spoiled me - I now find using TFS at work to be a bit of a drag and want to explore the possibility of using Git locally and syncing somehow with TFS. I figure there are a few ...

热门标签