2016-09-28 123 views
0

我正在将SVN存储库迁移到Git存储库。如何为存储库中的所有分支创建.gitignore?

一旦我迁移了,我将SVN分支和标签转换成Git分支和标签。

但是我尝试使用以下命令将.gitignore添加到所有分支。它总是添加到当前工作分支。

git svn show-ignore > .gitignore 

如何为所有分支添加.gitignore而不是当前分支中的命令在执行中。

回答

0

您可以遍历分支并使用cherry-pick来应用包含gitignore文件的提交。

你可以使用这样的脚本(git-apply-to-all-branches.sh):

#!/usr/bin/env bash 

sha=$1 

# get current branch name 
# http://stackoverflow.com/a/1593487/1401409 
branch_name="$(git symbolic-ref HEAD 2>/dev/null)" || 
branch_name="(unnamed branch)"  # detached HEAD 
branch_name=${branch_name##refs/heads/} 

# iterate over all branches 
git for-each-ref refs/heads | cut -d/ -f3- | while read branch; 
do 
    # skip current branch 
    [ $branch == $branch_name ] && continue 

    git checkout $branch 
    git cherry-pick $sha 
done 

而且假设你刚刚提交您的当前分支gitignore你可以调用:

./git-apply-to-all-branches.sh <sha_of_your_gitignore_commit> 
+0

可以写没有樱桃采摘脚本? – virendrao

+0

另一种方法是将show-ignore的输出放在.git/info/exclude中,如文档中所建议的那样。 https://git-scm.com/docs/git-svn#_basic_examples。那么你甚至不需要提交它。 – loopkin

+0

但这种影响将保留在本地存储库..如果我推到远程存储库其他开发人员拉和推代码,其中包括忽略的文件,那么它不会正常工作 – virendrao

相关问题