为什么我可以改变但我不能合并git?

时间:2015-03-31 17:58:05

标签: git merge rebase

也许你可以纠正我,我担心这可能很简单:

所以,从我的理解来看,git merge和git rebase是实现相同目标的两种不同方式:因此,如果我可以改变,我也可以合并。

现在,我正在尝试将 mybranch 与master合并,但是当我从 mybranch 开始时,

git merge master

我得到了#34;已经是最新的",虽然有几个不同之处,当我做的时候

git rebase master

它开始变基础。另外,当我修复一些冲突时,添加固定文件并执行

git rebase --continue

我收到了这个错误:

Applying: my commit xxx
No changes - did you forget to use 'git add'?
If there is nothing left to stage, chances are that something else
already introduced the same changes; you might want to skip this patch.

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".

以下是目前的情况:

*   179dcec (origin/myBranch, myBranch) Merge branch 'myBranch' of https://github.com/repo/myRepo into myBranch
|\  
| *   ee8525b Merge branch 'myBranch' of https://github.com/repo/myRepo into myBranch
| |\  
| | * 975a4f2  changed the name
| | * 153450b  Fixed jshint problems
| | *   b6eee76 Merge branch 'master' of https://github.com/repo/myRepo into myBranch
| | |\  
| | * | 70e3139  Fixed a bug
| | * | 715d308  fixed a bug
| | * |   ccfd06a Merge branch 'master' of https://github.com/repo/myRepo into myBranch
| | |\ \  
| | * | | 03c87f2  deleted useless test file
| | * | | dd09f21 Testing
| | * | | 214af56  Integrated the unified DB
| | * | |   43242ff Merge branch 'master' of https://github.com/repo/myRepo into myBranch
| | |\ \ \  
| | * \ \ \   f9ecae6 Merge branch 'master' of https://github.com/repo/myRepo into myBranch
| | |\ \ \ \  
| | * | | | | 626bb26  Error handler integrated
| | * | | | |   ac92b60 Merge branch 'master' of https://github.com/repo/myRepo into myBranch
| | |\ \ \ \ \  
| | * \ \ \ \ \   9f6c0b2 Merge branch 'master' of https://github.com/repo/myRepo into myBranch
| | |\ \ \ \ \ \  
| | * | | | | | | b09ce40  added DB error handler
| * | | | | | | | d3ebb13  changed the name
| * | | | | | | | f68281e  Fixed jshint problems
| * | | | | | | | 31cb0b3  Fixed a bug
| * | | | | | | | 74d8735  fixed a bug
| * | | | | | | | cb3e6e2  deleted file
| * | | | | | | | 80d7164 Testing
| * | | | | | | | 191fb77  Integrated the unified DB
| * | | | | | | | 2af7142  Error handler integrated
| * | | | | | | | fff8b2f  added DB error handler
| | |_|_|_|_|_|/  
| |/| | | | | |  
* | | | | | | | 730b412  deleted useless test file

这里发生了什么?

1 个答案:

答案 0 :(得分:0)

  

从我如何理解它git merge和git rebase是实现相同目标的两种不同方式:因此如果我可以rebase我也可以合并

确实,rebase和merge将(假设任何合并冲突以相同的方式得到解决)在最终的提示中结束相同的内容 - 但是rebase为每个重新提交的提交进行新的提交,顺序重放新基本提交内容(master此处)中每个内容的更改。 Merge保留当前历史记录,并添加一个新提交,其中包含每个分支上所有提交的更改,因为合并基础只合并为一个新的提交。

如果您记住每个提交都是完整内容,这将更容易理解:对于merge,git只是将左分支的尖端与合并基础区分开来,将右分支的尖端与合并基础区分开来结合所有看起来独立的帅哥,让你理清任何看起来可能会发生冲突的帅哥。如果你不得不这样做,那就是你自己做的完全相同的差异/补丁序列。

因此,您可以将rebase视为追溯性合并。