[英]Git merging into branch with changes to both since split
Suppose I am on branch master
and run git branch dev
- this will create a new branch. 假设我在分支
master
并运行git branch dev
这将创建一个新分支。
Then I make some changes to branch dev
然后我对分支
dev
进行一些更改
Then I make some completely different changes to branch master
, but some are to the same file 然后,我对分支
master
进行了完全不同的更改,但对同一文件进行了一些更改
master -> (arbitrary # of commits) -> master*
\
\___ dev -> (arbitrary # of commits) -> dev*
And now I run git merge
现在我运行
git merge
Changes made to dev
will be added to master
对所做的更改
dev
将被添加到master
Q1) Will changes made to master
be overwritten? Q1)对
master
所做的更改是否会被覆盖?
Q2) What if the changes made to dev
are to the same file as the changes made to master
? Q2)如果对
dev
所做的更改与对master
所做的更改在同一文件中怎么办?
Q2b) What if I want changes to one branch to take priority? Q2b)如果我希望对一个分支的更改具有优先权怎么办?
For example: test.js
was changed on lines 2-7 in master
but it was changed on lines 5-10 in dev
. 例如:
test.js
在master
2-7行中更改,但在dev
5-10行中更改。
What if I want the changes in master
to take priority. 如果我要优先更改
master
怎么办。 That is, I want this merge
to ignore all changes to test.js
from dev
也就是说,我希望此
merge
忽略dev
对test.js
所有更改
Git merge does exactly as it says. Git merge完全按照它所说的进行。 It'll merge your changes.
它将合并您的更改。
$ git checkout master $ git merge dev
This will merge all your changes from dev into master. 这会将您所做的所有更改从开发合并到主。 Depending on the severity of the merge it'll create a separate merge commit (you'll have to step through that commit and write a commit message).
根据合并的严重性,它将创建一个单独的合并提交(您将必须单步执行该提交并编写一条提交消息)。
git merge --abort
if you start panicking). git merge --abort
)。 This is a great example for why a test suite is important. 这是测试套件为何如此重要的一个很好的例子。 It's a fast way to see when merges have gone bad, because your tests might fail on bad merges.
这是查看合并何时变坏的快速方法,因为在合并失败时测试可能会失败。
The documentation for git merge has great examples, too. git merge的文档也有很好的例子。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.