![](/img/trans.png)
[英]Merge a git repository lacking commits history to a repository that preserved history
[英]Prune empty merge commits from history in Git repository
我已經清理了我們的Git存儲庫,我們需要從歷史中刪除大部分內容。 我這樣做使用:
git filter-branch --prune-empty --tree-filter 'rm -rf some_stuff'
--prune-empty
標志將刪除在進程后保留為空的提交,除了具有多個父項的提交(合並提交)。 即使合並的分支完全沒有包含任何內容,合並也不會向樹添加任何內容。
我如何從歷史中修剪這些空的合並提交?
我需要在ssokolow / profile的副本上運行filter-branch
后將 ssokolow / lap分開。
這是一個不錯的工作,作為一個自動“崩潰任何留下殘余的--prune-empty
”命令:
git rebase --root HEAD
(我需要--root
所以它會用最舊的仍然有內容的初始提交替換現在空的初始提交。)
這看起來對我有用 : http : //git.661346.n2.nabble.com/Removing-useless-merge-commit-with-quot-filter-branch-quot-td7356544.html
git filter-branch -f --prune-empty --parent-filter FULL_PATH_TO/rewrite_parent.rb master
rewrite_parent.rb
:
#!/usr/bin/ruby
old_parents = gets.chomp.gsub('-p ', ' ')
if old_parents.empty? then
new_parents = []
else
new_parents = `git show-branch --independent #{old_parents}`.split
end
puts new_parents.map{|p| '-p ' + p}.join(' ')
所以我的解決方案是將所有內容移動到sub-dir(歷史上)然后--subdirectory-filter
我修改了一下sh文件:
#!/bin/bash
git ls-files -s | sed "s-\t-&temp_dir/-" | GIT_INDEX_FILE="$GIT_INDEX_FILE.new" git update-index --index-info
mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE" || true
跑
git filter-branch --index-filter '~/doit.sh' HEAD
第二步
git filter-branch --subdirectory-filter temp_dir --prune-empty
推它。
我在filter-branch周圍發現了一個非常可愛的小包裝腳本:
https://github.com/pflanze/chj-bin/blob/master/cj-git-filter-branch
這里的前提和背景:
http://lists.q42.co.uk/pipermail/git-announce/2011-September/000486.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.