如何进入当前分支? [英] How to pull into not-the-current-branch?
问题描述
说我当前的分支是myfeature.我想掌握最新的知识.据我所知,两个git merge
git pull
都始终合并到当前分支中.
Say my current branch is myfeature. I want to get master up to date. Both git merge
git pull
always merge into the current branch, as far as I can tell.
是否可以将更改从远程分支(例如,源/主服务器)合并到我当前不在的分支(主服务器)中?我可以想到一种方法:
Is there a way to merge changes from a remote branch (eg, origin/master) into a branch I'm not currently on (master)? I can think of one way:
git stash
git checkout master
git pull origin/master
git checkout myfeature
git stash apply
有更好的一个吗?
(这可能是我的整个问题是错误的:如果启用了远程跟踪,git fetch
是否会自动更新母版以匹配原始/母版?)
(It's possibly my whole question is wrong: would git fetch
automatically update master to match origin/master, if remote-tracking is enabled?)
推荐答案
您正确的是,pull/merge只合并到当前分支中.
You are correct that pull/merge only merges into the current branch.
但是,您仍然可以使用访存.例如(以下名称更改以保护无辜者,但哈希是真实的):
You can, however, still use fetch. For instance (names below changed to protect the innocent but the hashes are real):
$ git branch | grep '^*'
* SOMEBRANCH
$ git rev-parse OTHER_BRANCH origin/OTHER_BRANCH
7b9b8e57cf19964b60ebda0f03a1d5da3de9e2fe
7b9b8e57cf19964b60ebda0f03a1d5da3de9e2fe
$ git fetch
7b9b8e5..1efca56 OTHER_BRANCH -> origin/OTHER_BRANCH
$ git rev-parse OTHER_BRANCH origin/OTHER_BRANCH
7b9b8e57cf19964b60ebda0f03a1d5da3de9e2fe
1efca56c08b7a0f511a3951195656a798c56aa62
在这种情况下,fetch
更新了一堆起源/分支.没有更新任何本地分支(这些分支的git rev-parse
输出保持不变),但是新提交现在位于存储库中并且可以查看(git log origin/OTHER_BRANCH
,gitk --all
等).
In this case, fetch
updated a bunch of origin/ branches. None of the local branches were updated (git rev-parse
output for those remains the same) but the new commits are now in the repo and can be viewed (git log origin/OTHER_BRANCH
, gitk --all
, etc).
根据您的需求,这可能就足够了.特别是,您可以看到需要从origin/master
应用于master
的所有内容,而无需离开当前分支.
Depending on your needs, this might be sufficient. In particular you can see what needs to be applied from origin/master
onto master
, all without leaving your current branch.
这篇关于如何进入当前分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!