1

I am working on migrating SVN repository to Git repository.

Once i have migrated, i convert SVN branches and tags into Git branches and tags.

However i tried adding .gitignore to all branches using following command. It always adds to current working branch.

 git svn show-ignore > .gitignore

How can i add .gitignore for all branches rather than current branch where command in executed.

virendrao
  • 1,763
  • 2
  • 22
  • 42

1 Answers1

1

You could iterate through the branches and use cherry-pick to to apply your commit containing the gitignore files.

You could use a script like this (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

And assuming you just committed your gitignore on the current branch you can invoke:

./git-apply-to-all-branches.sh <sha_of_your_gitignore_commit>
scharette
  • 605
  • 1
  • 9
  • 25
  • possible to write script without cherry-pick? – virendrao Sep 29 '16 at 05:08
  • Another option would be to place the output of show-ignore in .git/info/exclude as suggested in the documentation. https://git-scm.com/docs/git-svn#_basic_examples. Then you would not even need to commit it. – scharette Sep 29 '16 at 12:22
  • but this impact will remain at local repository.. if i push to remote repository other developers pull and push code which includes ignored file then it wont work right – virendrao Sep 29 '16 at 12:46
  • this is correct. I'm not sure how git svn show-ignore behaves, but if it can give a different output based on the branch you are on (because your code structure might have changed) you might want to replace the cherry-pick in the script above by a call to show-ignore and a commit. So it would create a .gitignore specific to each branch instead of reusing the one from the trunk. – scharette Sep 29 '16 at 13:10