简体   繁体   中英

git-svn and unfortunate svn pre-commit hooks

I have a git repository with about 30 revisions that I want to import into an existing SVN repository. Unfortunately the SVN repository has a bunch of pre-commit hooks requiring certain information in commit messages, certain SVN keywords in certain file types, and so on. None of these are really relevant to to the stuff I'm checking in, or at any rate, they're not as important as keeping the existing revision history.

In a perfect world, I maybe could do something like:

  1. hijack the first git revision (and any other revisions that introduce new files) to make it include the necessary SVN keywords and set the corresponding svn:keywords property
  2. mass-edit all 30 git commit messages to prepend the required commit-message strings

In a somewhat less perfect world, I could get git-svn to somehow prepend skip-pre-commit-checks (? -- I've never used it before), and then I'd at least have all the revision history in there.

Thoughts?


Updated to add: skip-pre-commit-checks isn't actually a thing; I was misled by a specific hack at a particular project.

You have a few options.

Bulk-rewrite commit messages

You can use git filter branch to rewrite your commit messages:

If you need to add Acked-by lines to, say, the last 10 commits (none of which is a merge), use this command:

git filter-branch --msg-filter '
    cat &&
    echo "Acked-by: Bugs Bunny <bunny@bugzilla.org>"
' HEAD~10..HEAD

Manual editing of 30 commit messages

You can git rebase interactive to rewrite your commit messages by selecting edit mode

git rebase -i HEAD~30

edit f7f3f6d changed my name a bit
edit 310154e updated README formatting and added blame
edit a5f4a0d added cat-file
...

Then

git commit -v --amend
<editor launched, edit commit message>
git rebase --continue
git commit -v --amend
<editor launched, edit commit message>
git rebase --continue
git commit -v --amend
<editor launched, edit commit message>
git rebase --continue
....

Squash everything into one commit

You can also use git rebase to squash everthying into one commit limiting your workload

git rebase -i HEAD~30

pick f7f3f6d changed my name a bit
squash 310154e updated README formatting and added blame
squash a5f4a0d added cat-file
...

<editor launched, edit the combined commit message>

Proactive Automation

If this is something you're likely to need to do regularly, you can use the prepare commit mesg hook to add some consistency to the format of your commit messages.

Note that, unlike git, you can't skip pre-commit hooks in svn (at least not by any built in mechanism) so attempting to do anything like git commit -va --no-verify will have no effect as the next time you run git svn dcommit , it'll fail all the same (if there's something to fail for of course).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM