我是Git新手。我最近把一个Rails项目从Subversion转移到Git。我遵循了这里的教程:http://www.simplisticcomplexity.com/2008/03/05/cleanly-migrate-your-subversion-repository-to-a-git-repository/

我还使用unfuddle.com来存储我的代码。我在上班/下班的火车上对我的Mac笔记本电脑进行更改,然后在我有网络连接时,使用以下命令将它们推到不稳定状态:

git push unfuddle master

我使用Capistrano进行部署,并使用主分支从unduddle存储库中提取代码。

最近,当我在笔记本电脑上运行“git status”时,我注意到下面的消息:

# On branch master
# Your branch is ahead of 'origin/master' by 11 commits.
#
nothing to commit (working directory clean)

我很困惑为什么。我以为我的笔记本电脑是源头…但不知道是否我最初从Subversion或推送到unduddle是导致消息显示的原因。我怎样才能:

找出Git认为“源/主”在哪里? 如果是在其他地方,我如何把我的笔记本电脑变成“源/主”? 让这条信息消失。这让我觉得Git对某些事情不满意。

我的mac运行的是Git 1.6.0.1版本。


当我按照dbr的建议运行git remote show origin时,我得到以下结果:

~/Projects/GeekFor/geekfor 10:47 AM $ git remote show origin
fatal: '/Users/brian/Projects/GeekFor/gf/.git': unable to chdir or not a git archive
fatal: The remote end hung up unexpectedly

当我按照Aristotle Pagaltzis的建议运行git remote -v时,我得到以下结果:

~/Projects/GeekFor/geekfor 10:33 AM $ git remote -v
origin  /Users/brian/Projects/GeekFor/gf/.git
unfuddle    git@spilth.unfuddle.com:spilth/geekfor.git

现在,有趣的是,我在geekfor目录中处理我的项目,但它说我的原点是gf目录中的本地机器。我相信gf是我在将项目从Subversion转换到Git时使用的临时目录,可能也是我从那里推送到unduddle的地方。然后我相信我检查了一个新的副本从unuddle到geekfor目录。

所以看起来我应该遵循dbr的建议,这样做:

git remote rm origin
git remote add origin git@spilth.unfuddle.com:spilth/geekfor.git

当前回答

我也在想我的回购。以我为例,我有一个旧遥控器,我不再按它了,所以我需要把它拿走。

获取遥控器列表:

git remote

删除你不需要的那个

git remote rm {insert remote to remove}

其他回答

我以为我的笔记本电脑是源头…

这有点荒谬:origin指的是默认的远程存储库——您通常从中获取/提取其他人的更改。

我怎样才能:

git remote -v will show you what origin is; origin/master is your “bookmark” for the last known state of the master branch of the origin repository, and your own master is a tracking branch for origin/master. This is all as it should be. You don’t. At least it makes no sense for a repository to be the default remote repository for itself. It isn’t. It’s merely telling you that you have made so-and-so many commits locally which aren’t in the remote repository (according to the last known state of that repository).

当我推送到远程存储库时,我遇到了“你的分支在nn提交的'origin/master'之前”的问题:

git push ssh://git@xxx.repositryhosting.com/yyy/zzz.git

当我发现我的远程地址在文件。git/FETCH_HEAD和使用:

git push

问题消失了。

【解决方案】

$ git push origin

这为我解决了问题。 它做了什么,它同步我的主(在笔记本电脑上)与“原点”,这是在远程服务器上。

1. 用Git -remote找出Git认为“origin/master”在哪里

git remote show origin

..它将返回类似于..

* remote origin
  URL: me@remote.example.com:~/something.git
  Remote branch merged with 'git pull' while on branch master
    master
  Tracked remote branch
    master

远程基本上就是到远程存储库的链接。当你…

git remote add unfuddle me@unfuddle.com/myrepo.git
git push unfuddle

..Git会将更改推送到您添加的地址。它就像一个书签,用于远程存储库。

当您运行git status时,它会检查远程存储库是否缺少提交(与本地存储库相比),如果是,则检查提交的数量。如果你把所有的更改都推到“原点”,两者都会同步,所以你不会收到那个消息。

2. 如果是在其他地方,我如何把我的笔记本电脑变成“源/主”?

这样做毫无意义。说“origin”被重命名为“laptop”-你永远不想从你的笔记本电脑上做git push laptop。

如果你想删除原始远程,你可以这样做。

git remote rm origin

这不会删除任何东西(在文件-内容/修订-历史方面)。这将停止“您的分支领先于..”消息,因为它将不再将您的存储库与远程存储库进行比较(因为它已经消失了!)

有一件事要记住,关于origin没有什么特别的,它只是git使用的默认名称。

当你执行Git push或Git pull之类的操作时,Git默认使用origin。所以,如果你有一个经常使用的遥控器(在你的情况下是unuddle),我建议添加unuddle作为“origin”:

git remote rm origin
git remote add origin git@subdomain.unfuddle.com:subdomain/abbreviation.git

或者使用set-url在一个命令中执行上述操作:

git remote set-url origin git@subdomain.unfuddle.com:subdomain/abbreviation.git

然后你可以简单地做git push或git pull来更新,而不是git push unuddle master

我最近遇到了这个问题,我想这是因为我删除了一些我不再需要的文件。问题是git不知道文件已经被删除了,它看到服务器上还有文件。(server = origin)

所以我跑了

git rm $(git ls-files --deleted)

然后运行commit和push。

这就解决了问题。