为了账号安全,请及时绑定邮箱和手机立即绑定

如何使git始终从特定分支中提取?

如何使git始终从特定分支中提取?

Git
一只斗牛犬 2019-11-21 10:32:47
我不是git master,但是我已经和它一起工作了一段时间了,并且有几个不同的项目。当然,在每个项目中,从那时git clone [repository]起,我始终可以git pull,并且只要没有特别的变化,我就可以始终如此。最近,我不得不还原到上一个分支,并使用进行了此操作git checkout 4f82a29。当我再次准备拉动时,我发现必须将分支设置回master。现在,我不能使用直线git pull,而是必须指定git pull origin master,这很烦人,并向我表明我不完全了解发生了什么。发生了什么变化,哪些使我无法在git pull不指定原点大师的情况下进行平直比赛?如何更改它?更新:-bash-3.1$ cat config[core]    repositoryformatversion = 0    filemode = true    bare = false    logallrefupdates = true[branch "master"][remote "origin"]    url = git@github.com:user/project.git    fetch = refs/heads/*:refs/remotes/origin/*更新2:明确地说,我知道我的原始方法可能不正确,但是我需要修复此存储库,以便可以git pull再次使用。目前,git pull导致:-bash-3.1$ git pullYou asked me to pull without telling me which branch youwant to merge with, and 'branch.master.merge' inyour configuration file does not tell me either.  Pleasename which branch you want to merge on the command line andtry 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 toconfigure the following variables in your configurationfile:    branch.master.remote =     branch.master.merge =     remote..url =     remote..fetch = See git-config(1) for details.我可以说出git pull要合并的分支,它可以正常工作,但git pull不能像原来的分支那样工作git checkout。
查看完整描述

3 回答

?
慕哥6287543

TA贡献1831条经验 获得超10个赞

在下[branch "master"],尝试将以下内容添加到仓库的Git配置文件(.git/config):


[branch "master"]

    remote = origin

    merge = refs/heads/master

这告诉Git 2件事:


当您在master分支上时,默认的遥控器是origin。

在git pullmaster分支上使用(未指定任何远程和分支)时,请使用默认的remote(来源)并合并来自remote master分支的更改。

我不确定为什么会从您的配置中删除此设置。您可能也必须遵循其他人发布的建议,但这可能有用(或至少有帮助)。


如果您不想手动编辑配置文件,则可以使用命令行工具:


$ git config branch.master.remote origin

$ git config branch.master.merge refs/heads/master


查看完整回答
反对 回复 2019-11-21
  • 3 回答
  • 0 关注
  • 534 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信