我有一个远程跟踪分支在我的本地存储库中使用'git分支-b分支名称起源/分支名称‘进行本地跟踪。我的远程分支是test2/test2 (源/分支名称),它在本地被跟踪为test2。
原点也被命名为test2。我还没有检查我的本地跟踪分支test2。
当我执行'git pull origin remote-branch:local-tracked-branch‘时,我得到这个错误
test2$ git从/ test2 /git_bare/test2中拉出test2!rejected test2 -> test2 (非快进)
然而,当我签出我的本地跟踪分支test2并拉出'git pull origin local-tracked- branch‘时,我没有得到错误,我使用'git pull test2 test2’进行了拉出
From /gitvobs/git_bare/test2 * branch test2 -> FETCH_HEAD自动合并a.txt自动合并失败;修复冲突,然后提交结果。
我知道添加一个+ (git pull test2 +test2:test2)会有所帮助,但它会覆盖本地更改。
那么,我如何知道我的哪些本地分支是由我使用'git branch new- branch-name‘在本地创建的,还是使用git branch -b分支名称源/分支名称’从远程分支本地跟踪的?
发布于 2010-05-22 15:30:22
与跟踪的分支列表(您可以使用git config -l查看)无关,"non-fast-forward" message方法不能合并您的分支中的远程分支(即远程分支的获取提交的本地副本),因为:
,而远程分支自上次pull
以来有新的提交
所以:
--last pull
|
v
x-x-x-x-x <--test2
\
-y-y-y <-- test2/test2而这将是一次快进合并
--last pull
|
v
x-x <--test2
\
-y-y-y <-- test2/test2所以:
git checkout test2
git fetch test2 test2
git merge test2/test2
#fix conflicts
git commit另外,请将您的远程存储库命名为test2以外的任何名称。这里的test2太多了;)
现在查看本地存储库中跟踪的远程分支的列表:
git config --get-regexp branch..*发布于 2010-05-23 05:22:15
git拉取混淆
过度专一性
您的git pull命令包含的信息太多。
test2$ git拉取test2 test2:test2
来自/gitvobs/git_bare/test2
好了!rejected test2 -> test2 (非快进)
我知道添加一个+ (git pull test2 +test2:test2)会有所帮助,但它会覆盖本地更改。
这就是您的命令的含义:
# *------------ (1) remote repository name
# / *------- (2) ref in remote repository
# / / *-- (3) ref in local repository
# / / /
git pull test2 test2:test2
# Means this: From remote repository `test2` (1),
# fetch branch `test2` (2), store it in local branch `test2` (3), then
# merge the fetched history into HEAD.您告诉git pull用远程服务器上的test2分支覆盖本地的test2分支,然后将其与HEAD合并。您可能不希望包含refspec的目标部分( :test2)。
如果您签出的本地分支被配置为跟踪某些内容(请参阅“分支:…”下面),只需执行
git pull如果您需要提供(或覆盖)远程和存储库,只需提供远程名称/url和远程上的本地分支(忽略refspec的最后一部分):
git pull test2 test2拉入未检出的分支
git pull (如上所述)是git fetch和git merge (或git rebase)的组合。
一般而言,合并可能涉及冲突解决。冲突解决需要一个工作树。因此,如果没有工作树,就不可能执行正常的合并操作。这意味着您当前的头必须是合并的父对象之一(它将是第一个父对象)。执行rebase还需要一个用于冲突解决的工作树。
由于拉入涉及合并或重新建立基础,因此不可能拉入未检出的本地分支。您只能拉入当前已检出的分支。
分支:本地、跟踪、远程跟踪
各种类型的Git分支都是相同的底层对象: refs。Ref位于$GIT_DIR/refs/和$GIT_DIR/packed-refs中的refs/名称空间中。
refs/heads/名称空间中。检查git show-ref refs/heads/test2,或cat .git/refs/heads/test2,orgrep -F refs/heads/test2 .git/packed-refs本地分支的
refs/remotes/<remote-name>/名称空间中。)这个不幸命名的分支功能混淆。
- To examine the `test2` remote tracking branch ref:
- `git show-ref refs/remotes/test2/test2`, or
- `cat .git/refs/remotes/test2/test2`, or
- `grep -F refs/remotes/test2/test2 .git/packed-refs`
跟踪另一个分支的
refs/heads/中),在远程分支“$GIT_DIR/config”remote = test2 merge =refs/head/test2中有额外的配置重要的是要注意,merge (或rebase)配置选项在远程服务器上命名一个ref。因此,这里的refs/heads/test2是指在远程test2上找到的本地分支test2。特殊的远程名称.可用于引用本地存储库中的本地分支。
- The purpose of local branches that “track” some other branch is to make it easy to just type `git pull` and have it merge in (or rebase on top of) the history in some other branch.
您说过要区分普通的本地分支和跟踪其他分支的本地分支。您可以通过在$GIT_DIR/config文件中查找分支配置来完成此操作。
您可以使用git config来完成此操作:
branch_tracks_something() {
{
git config branch."$1".merge ||
git config branch."$1".rebase
} >/dev/null 2>&1
}
# test local branch
branch_tracks_something test2 && echo 'test2 tracks something' || echo 'test2 does not track anything'或者,如果您使用的是Git1.6.3或更高版本,则可以使用%(upstream)格式的Git for-each-ref
{ echo 'show_ref_desc() {
case "$1" in
refs/heads/*)
t=''
test -n "$2" && t=" (tracks $2)"
echo "local: $1$t"
;;
refs/remotes/*)
echo "remote tracking: $1"
;;
*)
echo "other: $1"
;;
esac
}'; git for-each-ref --shell --format='show_ref_desc %(refname) %(upstream)'; } |
sh输出如下所示:
local: refs/heads/test2 (tracks refs/remotes/test2/test2)
remote tracking: refs/remotes/test2/HEAD
remote tracking: refs/remotes/test2/test2https://stackoverflow.com/questions/2887242
复制相似问题