[英]“Importing” changes from a branch to a rebased branch with git
I've been working on a project foo that is a fork of another project bar , doing branch and so on. 我一直在研究项目foo ,它是另一个项目栏的分支,进行分支等。 I'd like now to offer my changes to the original project too. 我现在也想对原始项目进行更改。
Firstly I have set up things for the future rebase: 首先,我为将来的基础设置了一些东西:
git remote add bar git://bar/bar.git
git fetch bar
git checkout -b bar-master bar/master
Now, for a given branch foo-branch made for the project foo , I have ran: 现在,对于为项目foo制作的给定分支foo-branch,我已经运行:
git checkout foo-branch
git checkout -b bar-branch
git checkout bar-branch
git rebase bar-master
I can see from: 我可以从中看到:
git log --format=one
that the rebase went OK. 重新安装正常。
Now I'm going to do changes/commits in either foo-branch or bar-branch. 现在,我将在foo-branch或bar-branch中进行更改/提交。
My question is: how can I "import" the commits from one branch (eg foo-branch) onto the branch for the other project (in the given example, bar-branch)? 我的问题是:如何将提交从一个分支(例如foo-branch)“导入”到另一个项目的分支(在给定示例中为bar-branch)?
After rebase
you could simply merge the data, this will be fast-forward merge
so it wouldn't introduce any merge commits. 重新设置rebase
之后,您可以简单地合并数据,这将是fast-forward merge
因此不会引入任何合并提交。
Or.. if you want single commit, you could use cherry-pick
git command Or.. if you want many commits being imported at once you could use rebase
with --onto
switch. 或者..如果要单次提交,则可以使用cherry-pick
git命令;或者..如果要一次导入许多提交,则可以使用带有--onto
rebase
开关。
So since you've rebased your fork with the upstream (original) repo, your all set for a fast-forward merge - and thats a great start. 因此,由于您已经使用上游(原始)存储库对fork进行了基础调整,因此所有设置都可以进行快速合并-这就是一个很好的开始。
To push to different repos, you simply specify the given repo in your push command. 要推送到其他存储库,只需在push命令中指定给定的存储库即可。 To push to foo
you would run... 要推到foo
您将运行...
git push foo <branch-name>
To bush to the bar
repo, run... 要穿梭于bar
回购,请运行...
git push bar <branch-name>
To pull from foo or bar, its the same set of commands, but with pull instead of push. 从foo或bar进行拉取,其命令集相同,但使用pull而不是push。
Its useful to understand that because git is already treating foo and bar as separate remotes, you dont need to make a special branch for each repo. 理解这很有用,因为git已经将foo和bar视为单独的远程对象,因此您无需为每个存储库都创建一个特殊的分支。 Git already does this for you behind the scenes. Git已在后台为您完成此操作。 Run the following set of commands with the same <branch>
to see what I mean 使用相同的<branch>
运行以下命令集,以了解我的意思
git log foo/<branch>
git log bar/<branch>
When you run a git pull
command, thats a shortcut for git fetch <remote>
and git merge <branch>
. 当您运行git pull
命令时,这就是git fetch <remote>
和git merge <branch>
的快捷方式。 When you run a fetch command, git creates/updates all that branches repositories on your local repository - all naming convention of <remote-name>/<branch-name
. 当您运行fetch命令时,git会创建/更新本地存储库中所有分支存储库-所有<remote-name>/<branch-name
命名约定。 These aren't branches you can directly checkout, but you can run logs against them, merge from and and rebase from them. 这些不是您可以直接检出的分支,但是您可以针对它们运行日志,从它们合并并根据它们重新设置基础。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.