git 如何从本地分支“拉”到另一个分支?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5613902/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 10:35:30  来源:igfitidea点击:

How to "pull" from a local branch into another one?

git

提问by Phil Kulak

This sounds so simple, but I just can't figure it out. I made an experimental branch a while ago, and now I'd like to pull in all the changes that happened on master since I made it. This is all local. I want to pull from local master into local my_branch, but I can't do it. This doesn't seem to work, telling me that master isn't a git repository:

这听起来很简单,但我就是想不通。不久前我创建了一个实验分支,现在我想引入自创建以来在 master 上发生的所有更改。这都是本地的。我想从本地 master 拉入本地 my_branch,但我做不到。这似乎不起作用,告诉我 master 不是 git 存储库:

git pull master

回答by knittl

you have to tell git where to pull from, in this case from the current directory/repository:

你必须告诉 git 从哪里拉,在这种情况下是从当前目录/存储库:

git pull . master

but when working locally, you usually just call merge (pull internally calls merge):

但是在本地工作时,您通常只调用merge(内部pull调用merge):

git merge master

回答by KingCrunch

What you are looking for is merging.

您正在寻找的是合并。

git merge master

With pullyou fetch changes from a remote repository and merge them into the current branch.

随着pull您从远程存储库中获取更改并将它们合并到当前分支中。

回答by Lukino

Quite old post, but it might help somebody new into git.

很旧的帖子,但它可能会帮助新进入 git 的人。

I will go with

我会一起去

git rebase master
  • much cleaner log history and no merge commits (if done properly)
  • need to deal with conflicts, but it's not that difficult.
  • 更干净的日志历史记录和没有合并提交(如果做得好)
  • 需要处理冲突,但这并不难。

回答by theRana

If you are looking for a brand new pull from another branch like from local to master you can follow this.

如果您正在寻找从另一个分支(例如从本地到 master)的全新拉取,您可以按照此操作。

git commit -m "Initial Commit"
git add .
git pull --rebase git_url
git push origin master