简体   繁体   English

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

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

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.前段时间我做了一个实验性的分支,现在我想提取自从我创建它以来在 master 上发生的所有更改。 This is all local.这都是本地的。 I want to pull from local master into local my_branch, but I can't do it.我想从本地 master 拉到本地 my_branch,但我做不到。 This doesn't seem to work, telling me that master isn't a git repository:这似乎不起作用,告诉我 master 不是 git 存储库:

git pull master

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(内部调用merge):

git merge master

What you are looking for is merging.您正在寻找的是合并。

git merge master

With pull you fetch changes from a remote repository and merge them into the current branch.使用pull您可以从远程存储库中获取更改并将它们合并到当前分支中。

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.需要处理冲突,但这并不难。

If you want to do the step 3 shown in the picture .如果您想执行图片中显示的第 3 步。 Then follow the step below.然后按照以下步骤操作。

  1. git switch b (make sure you are in the same branch where you want to merge) git switch b (确保您在要合并的同一分支中)
  2. git merge b ( this command indicating that you are merging b into a) git merge b (这个命令表明你正在将 b 合并到 a 中)

If you are looking for a brand new pull from another branch like from local to master you can follow this.如果您正在寻找从另一个分支(例如从本地到大师)的全新拉动,您可以按照此操作。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM