您如何让 git 始终从特定分支中提取? [英] How do you get git to always pull from a specific branch?

查看:17
本文介绍了您如何让 git 始终从特定分支中提取?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是 git 大师,但我已经使用它一段时间了,有几个不同的项目.在每个项目中,我总是git clone [repository],从那时起,我总是可以git pull,当然,只要我没有明显的变化.

I'm not a git master, but I have been working with it for some time now, with several different projects. In each project, I always git clone [repository] and from that point, can always git pull, so long as I don't have outstanding changes, of course.

最近,我不得不恢复到以前的分支,并使用 git checkout 4f82a29 这样做.当我再次准备 pull 时,我发现我必须将我的分支设置回 master.现在,我不能使用直接的 git pull 拉取,而是必须指定 git pull origin master,这很烦人,并向我表明我没有完全了解正在发生的事情.

Recently, I had to revert to a previous branch, and did so with git checkout 4f82a29. When I was again ready to pull, I found that I had to set my branch back to master. Now, I can not pull using a straight git pull but instead, have to specify git pull origin master, which is annoying, and indicates to me that I don't fully understand what is going on.

有什么变化不允许我在不指定 origin master 的情况下直接执行 git pull,以及如何将其改回来?

What has changed which does not allow me to do a straight git pull without specifying origin master, and how to I change it back?

更新:

-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:明确地说,我知道我原来的方法可能不正确,但我需要修复这个 repo,以便我可以再次使用 git pull.目前, git pull 结果为:

UPDATE 2: To be clear, I understand that my original method may have been incorrect, but I need to fix this repo so that I can simply use git pull again. Currently, git pull results in:

-bash-3.1$ 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 = 
    branch.master.merge = 
    remote..url = 
    remote..fetch = 

See git-config(1) for details.

我可以告诉 git pull 要合并哪个分支,并且它可以正常工作,但是 git pull 不能像在我的 git checkout 之前那样正常工作.

I can tell git pull which branch to merge, and it works correctly, but git pull does not work as it did originally before my git checkout.

推荐答案

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

Under [branch "master"], try adding the following to the repo's Git config file (.git/config):

[branch "master"]
    remote = origin
    merge = refs/heads/master

这告诉 Git 2 件事:

This tells Git 2 things:

  1. 当您在 master 分支上时,默认远程是 origin.
  2. 在 master 分支上使用 git pull 时,没有指定 remote 和 branch,使用默认的 remote(origin)并合并来自远程 master 分支的更改.
  1. When you're on the master branch, the default remote is origin.
  2. When using git pull on the master branch, with no remote and branch specified, use the default remote (origin) and merge in the changes from the remote master branch.

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

I'm not sure why this setup would've been removed from your configuration, though. You may have to follow the suggestions that other people have posted, too, but this may work (or help at least).

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

If you don't want to edit the config file by hand, you can use the command-line tool instead:

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

这篇关于您如何让 git 始终从特定分支中提取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆