更改存储库时的 git
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1434893/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git when changing the repository
提问by Tim
I am used to pull from a git repository of someone. Today he moved his repository to another address. I wonder if there is some way for me to pull from the new address and to get the info of what changes he made with respect to last time before his moving?
我习惯从某人的 git 存储库中提取。今天他把他的仓库搬到了另一个地址。我想知道是否有某种方法可以让我从新地址中提取并获取他在搬家前对上次所做的更改的信息?
What I have done is "git clone newaddress" under my repository pulled from his old one. The output is like:
我所做的是从他的旧存储库中提取的存储库下的“git clone newaddress”。输出是这样的:
got xxx
walk xxx
got xxx
got xxx
walk xxx
Getting alternates list for newaddress
Getting pack list for newaddress
Getting index for pack xxx
Getting pack xxx
which contains xxx
got xxx
got xxx
walk xxx
...
得到了 xxx
走xxx
得到了 xxx
得到了 xxx
走xxx
获取新地址的替代列表
获取新地址的装箱单
获取包装 xxx 的索引
得到包xxx
其中包含 xxx
得到了 xxx
得到了 xxx
走xxx
...
Then I "git pull" and got the following message which I don't understand:
然后我“git pull”并收到以下我不明白的消息:
You asked me to pull without telling me which branch you want to merge with, and 'branch.master.merge' in your configuration file does not tell me either. Please name which branch you want to merge on the command line and try again (e.g. 'git pull '). See git-pull(1) for details on the refspec.
If you often merge with the same branch, you may want to configure the following variables in your configuration file:
branch.master.remote = <nickname> branch.master.merge = <remote-ref> remote.<nickname>.url = <url> remote.<nickname>.fetch = <refspec>
See git-config(1) for details.
你让我拉而不告诉我你想合并哪个分支,你的配置文件中的“branch.master.merge”也没有告诉我。请在命令行上命名您要合并的分支并重试(例如“git pull”)。有关 refspec 的详细信息,请参阅 git-pull(1)。
如果你经常与同一个分支合并,你可能需要在你的配置文件中配置以下变量:
branch.master.remote = <nickname> branch.master.merge = <remote-ref> remote.<nickname>.url = <url> remote.<nickname>.fetch = <refspec>
有关详细信息,请参阅 git-config(1)。
What can I do now to still be able to get the info of what changes he made with respect to last time before his moving?
我现在该怎么做才能仍然能够获得他在搬家前对上次所做的更改的信息?
Thanks and regards!
感谢致敬!
回答by theIV
If I'm understanding your question correctly, what you are looking to do is replace your current remote origin with a new one. I don't know if you can replace it from command line, but you can change it in your .git/config
(this is in your project directory)
如果我正确理解了您的问题,那么您要做的是用新的远程源替换当前的远程源。我不知道你是否可以从命令行替换它,但你可以在你的.git/config
(这是在你的项目目录中)
OLD
老的
[remote "origin"]
url = git+ssh://original_repository.com/my_project.git
...
NEW
新的
[remote "origin"]
url = git+ssh://new_repository.com/my_project.git
...
The git+ssh
part might be something like git@
(this is what it would be if you were using github), or I'm sure a variety of other things. This might help clear up some things that I left out or didn't explain well enough: Changing Your Origin.
该git+ssh
部分可能类似于git@
(如果您使用 github,这就是它的内容),或者我确定还有其他各种内容。这可能有助于澄清一些我遗漏或解释得不够好的事情:改变你的起源。
Hope this helps answer your question. Cheers.
希望这有助于回答您的问题。干杯。
回答by VonC
Run this in your cloned git repository:
在克隆的 git 存储库中运行它:
git config branch.master.remote origin
to take care of the "You asked me to pull without telling me"... message.
照顾“你让我拉而不告诉我”......消息。
Then, if you know where the remote repo was moved, you could do in your new cloned local repo a git diff
since that date.
然后,如果您知道远程存储库被移动到哪里,您可以git diff
从该日期起在新克隆的本地存储库中执行操作。
$ git diff "@{yesterday}"
$ git whatchanged --since="2 weeks ago"
Note: the upcoming git1.6.5 mentions
注意:即将发布的git1.6.5 提到
Human writable date format to various options, e.g. "
--since=yesterday
", "master@{2000.09.17}
", are taught to infer some omitted input properly.
各种选项的人类可写日期格式,例如“
--since=yesterday
”、“master@{2000.09.17}
”,被教导正确推断一些省略的输入。
See also the SO question "How do you get git to always pull from a specific branch?"
另请参阅 SO 问题“如何让 git 始终从特定分支中提取?”