将本地代码库与Github项目合并

3
我有一个本地的github仓库,里面存储了一个旧版本的开源项目。我需要将本地仓库升级到Github上的新版本,但我不知道从哪里开始。
我看到一个例子,使用命令“git remote add {name} {URL of github repository}”。这个正确吗?我要用我的本地仓库替换{name}字段吗?
非常感谢任何建议。
我是Github的新手,不想破坏我的本地仓库,希望有经验的人能提供一些建议。
谢谢。
2个回答

2
  1. Add the remote repository (I've called it upstream here, you could call it everything):

    git remote add upstream {URL of github repository}
    
  2. Fetch all the commits, branches, tags, etc. from the upstream remote repo. This is a safe command and does not destroy your local repo's history or your working-tree.

    git fetch upstream
    
  3. You could run git log upstream/BRANCH_NAME or git log upstream/TAG_NAME to see the list of commits for the given BRANCH_NAME or TAG_NAME on the remote upstream. In fact for any of the git commands, if you want to refer to the branch present in the remote upstream, use the upstream/<BRANCH_NAME> syntax. For tags, tags/TAG_NAME should suffice.

  4. If you want to merge or rebase changes from these tags or branches into your local repo, you could do so using the merge and rebase commands. Let me know if you need more help on these commands.


我按照您的指示操作,但在想要合并特定标签时迷失了方向。我看到了我想要与我的仓库合并的标签名称。我需要执行类似于 "git merge --tag <标签名称>" 的操作吗? - loulou
哦,我想我可以这样做:“git merge tags/<tag name>”。我尝试了一下,可能有效。是这样吗? - loulou
感谢所有的帮助。 "git merge tags/tag_name" 似乎解决了问题 :) - loulou
如果您已经检出了存储库中的任何分支,并且想要合并名为FOO的上游标签,则可以执行git merge tags/FOO - Tuxdude

0

是的,那是正确的。

git remote add upstream git://github.com/antirez/redis.git

name 部分只是一个你选择的名称,以便于引用。

    Adds a remote named <name> for the repository at <url>. The command
    git fetch <name> can then be used to create and update
    remote-tracking branches <name>/<branch>.

如果我需要获取Github存储库的特定标签,该怎么办?有没有一种方法可以使用该命令指定特定版本?根据手册页面,似乎可以使用--tags选项。 - loulou
我尝试了带有“--tags”命令的标签名称和开源Github项目的URL,但没有任何反应。我的本地私有repo也是Github,我注意到该命令编辑了我的私有Github本地项目中的.git/config文件。我需要更改我的.git/config文件以指向开源项目吗? - loulou

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接