简体   繁体   English

Git:无法将功能分支合并到当前分支

[英]Git: Cannot merge feature branch to the current branch

I create a xxx branch from master and then create yyy from xxx branch.我从 master 创建了一个 xxx 分支,然后从 xxx 分支创建了 yyy。 There are 2 files in xxx branch and then I add one file after creatimng the branch yyy. xxx 分支中有 2 个文件,然后我在创建分支 yyy 后添加一个文件。 Now I want to apply the changes in the yyy branch to xxx branch by merge but after running the following:现在我想通过合并将 yyy 分支中的更改应用到 xxx 分支,但在运行以下命令后:

git checkout yyy
git merge xxx

It gives "Already up to date."它给出了“已经是最新的”。 message, but I do not see the changes on branch xxx, but the changes are seen on the branch yyy.消息,但我在分支 xxx 上看不到更改,但在分支 yyy 上看到了更改。 I mean that there are still 2 files in xxx and the added file is not seen.我的意思是xxx中还有2个文件,并且没有看到添加的文件。

So, my questions are:所以,我的问题是:

1. Is there any flag, etc that I should do in order to merge these 2 branch? 1.为了合并这两个分支,我应该做任何标志等吗?

2. Normally I use Gith Bash in order to run git commands. 2.通常我使用 Gith Bash 来运行 git 命令。 Is it better Git CMD? Git CMD 更好吗? And can I use cmd instead of git command lines?我可以使用 cmd 而不是 git 命令行吗? I mean is there any pros or cons between them?我的意思是它们之间有什么优点或缺点吗?

It looks like you have the things the other way around.看起来你有相反的事情。 You want to merge yyy to xxx, so you should do:你想将 yyy 合并到 xxx,所以你应该这样做:

git checkout xxx
git merge yyy

Git is right in saying that yyy is up to date, when you try to merge xxx, as yyy is based on xxx. Git 正确地说 yyy 是最新的,当您尝试合并 xxx 时,因为 yyy 是基于 xxx。

You can have a look at this tutorial:你可以看看这个教程:
https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging

I think you have your branches backwards in your commands.我认为您的命令中的分支向后。

According to this git cheatsheet根据 这个 git 备忘单

$ git checkout [branch-name]

  • Switches to the specified branch and updates the working directory切换到指定分支并更新工作目录

$ git merge [branch]

  • Combines the specified branch's history into the current branch ...指定分支的历史合并到当前分支...

For your case:对于您的情况:

If branch yyy has changes and you want to merge changes into branch xxx :如果分支yyy有更改并且您想将更改合并到分支xxx

$ git checkout xxx    --Checkout branch to update
$ git merge yyy       --Merge yyy changes into current branch

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

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