我一直在将旧的SVN回购转换为GIT.我已经获得了转换的分支和标签.包括在GIT中制作SVN标签真实标签.
但是,我想在新创建的GIT仓库的第一次提交中添加一个gitignore.我希望它好像文件一直在那里.因此,所有后面的提交(在主服务器或分支机构中)现在将具有此文件,因为父树将返回第一个提交.
似乎我需要某种形式的git rebase或git filter-branch --tree-filter.我已经尝试了其中的每一个,但我最终断开了分支机构.
Mas*_*ler 14
如果将来有人需要这样做,这是一个更简单的解决方案.我最近不得不修改早期提交,因为提交消息中存在问题拼写错误.这适用于更改先前提交的任何内容.我在这里修改了Charles Bailey的答案.
# Go back to the commit you want to change (detach HEAD)
git checkout <sha1_for_commit_to_change>
# Make any changes now (add your new file) then add them to the index
git add <new_files>
# amend the current commit
git commit --amend
# temporarily tag this new commit
# (or you could remember the new commit sha1 manually)
git tag tmp
# go back to the original branch (assume master for this example)
git checkout master
# Replay all the commits after the change onto the new initial commit
git rebase --preserve-merges --onto tmp <sha1_for_commit_to_change>
# remove the temporary tag
git tag -d tmp
Run Code Online (Sandbox Code Playgroud)
请注意,这将在修改后的提交后更改所有提交ID,因此不建议在公共存储库中使用.此外,您还必须重新创建所有标记
假设这是一个全新的重建,那么一个技巧是在第一次提交时启动一个分支并在那里添加 gitignore。您现在在该分支的头部拥有“正确”的提交。现在我们来看看技巧 - 您可以使用该grafts工具来重新排序感知的提交序列。普通的git filter-branch将使其永久化,尽管旧的层次结构仍将列在originalsrefs\info (IIRC) 中。
虽然这将创建包含 gitignore 文件的早期提交,但所有其他提交仍然不包含 gitignore 文件。
编辑:---------- git-filter-branch给出了示例:
git filter-branch --tree-filter 'rm filename' HEAD,和一个--index-filter变体。
您可以简单地add .gitignore使用 .gitignore 而不是删除,并使用 .gitignore ,--index-filter这样您的工作树仍然可以完整地进行复制。
不过,请先确保您有备份!报告它是否适合您。