git merge分支覆盖目的地

时间:2013-07-17 07:41:19

标签: git branching-and-merging git-merge

我的存储库有 master dev 分支。

目前我希望将 dev master 合并,或者更好,不是合并,而是完全替换带有 master dev 分支的内容

是否可以,以及如何使用git命令执行此操作?

2 个答案:

答案 0 :(得分:3)

这是与“他们的”策略的“合并”,doesn't exist natively

但你可以通过一种方式模拟它,如“git command for making one branch like another

我喜欢的是通过创建一个额外的分支:

git checkout dev
git checkout -b tmp
git merge -s ours master         # ignoring all changes from master
git checkout master
git merge tmp                    # fast-forward master to tmp HEAD
git branch -D tmp      

答案 1 :(得分:0)

假设您开始使用master ...稍后您创建了dev分支(来自master HEAD 或某些< em> master的先前提交 您还可以执行以下操作。

# find common ancestor

git merge-base master dev

# This will give you SHA-1 of ancestor like this: `4de51ba41fba357ac9ce63f098451cd1fc2dacbe`
# A hard reset master to this commit
git checkout master

git reset --hard 4de51ba41f

git rebase master dev

# After successful completion you will find yourself checked out on `dev`
# checkout master again and merge dev to get your final result

git checkout master

git merge dev

# Now your master will be same as dev