Dim*_*ele 14 git merge repository rebase
我想扩展我的另一个问题:合并两个Git存储库并保留主历史记录
我成功地将2个不同的回购合并为一个回购.我需要一个rebase才能成功地做到这一点.主人是正确的,但我也想保留合并历史记录.这可能吗?
我有2个存储库:
这是变基后的结果.顶级回购的时间是篮板时间.原来的日期丢失了!
我就这样做了:
# Assume the current directory is where we want the new repository to be created
# Create the new repository
git init
# Before we do a merge, we have to have an initial commit, so we'll make a dummy commit
dir > Read.md
git add .
git commit -m "initial commit"
# Add a remote for and fetch the old RepoA
git remote add -f RepoA https://github.com/DimitriDewaele/RepoA
# Do the same thing for RepoB
git remote add -f RepoB https://github.com/DimitriDewaele/RepoB
# Rebase the working branch (master) on top of repoB
git rebase RepoB/master
# Rebase the working branch (master with RepoB) on top op repoA
git rebase RepoA/master
Run Code Online (Sandbox Code Playgroud)
有可能有这样的东西吗?(画解决方案!!!)
我想保留原始时间+合并历史记录.
更新 - 答案
对我来说最有效的答案是使用嫁接点.但其他答案在其他用例中也非常有用.我在github上添加了我的结果,所以每个人都可以评估.
答案1:在我的情况下最好的工作 '贪污'确实为我揭示了正确的工作答案.
答案2 "LeGEC"中的"替换"选项也为某些用例提供了良好的结果.一个异常留给我:
答案3:值得加入 'VonC'的回答.在我的情况下,我无法获得"--preserve-merges working"选项.这可能适用于其他场景,但我没有测试这种情况.
正如您所发现的,rebase不是您想要用来将历史记录拼接在一起的命令(因为它实际上重写了历史记录).早期的Git有一个专门针对你要做的事情设计的特征(黑客):贪污点.更好,因为1.6.5你可以使用git replace --graft:
git checkout master
git replace --graft $(git log RepoB/master --format=%H | tail -1) HEAD
git replace --graft $(git log RepoA/master --format=%H | tail -1) RepoB/master
git reset --hard RepoA/master
Run Code Online (Sandbox Code Playgroud)
(git log RepoA/master --format=%H | tail -1返回初始提交RepoA)
从技术上讲,replace如果你还没有任何有价值的东西,你可以跳过第一个master,只产生RepoB + RepoA的历史.
这些命令创建的条目refs/replace/*可以推送和拉动以与其他人共享您修改的历史记录.或者,如果您不关心保留RepoA/RepoB的SHA,则可以通过运行生成所需的谱系的"真实"提交集来使替换永久化git filter-branch --all.
| 归档时间: |
|
| 查看次数: |
4920 次 |
| 最近记录: |