invalid author/committer line - missing space before email

纵然是瞬间 提交于 2019-12-02 00:39:14

问题


I have a git repository that was cloned from a bzr repository using git-remote-bzr as follows: git clone bzr::/repo new-repo. After a few hundreds of commits, I executed git fsck and I got the following error for all the bzr commits:

error in commit 41bf5: invalid author/committer line - missing space before email

When I check these revisions with git cat-file -p 41bf5 I can indeed see that the author name and the email are not separated with a space.

How can I add this missing space for all the bad commits ?

I have full access to the repo on the server so I can rewrite the history without any problems. After modifications the users of the code will have to reclone the repository. I already tried without success the solutions proposed in the following posts:

  • How do I change the author of a commit in git?
  • Change commit author at one specific commit

回答1:


The solution to my question came from a friend that asked me to write the answer on his behalf:

  1. Filter the repo, changing the bogus author with the following. Note that this should be on two separate lines (normally using shift+enter):

    $ git filter-branch --commit-filter 'case "$GIT_AUTHOR_NAME" in
    > *author\<\ email*) GIT_AUTHOR_NAME=author_name; GIT_AUTHOR_EMAIL=author_email;; esac; git commit-tree "$@" '
    
  2. Since the faulty commits are still in the repository, git fsck will still fail on them. To get rid of those commits, clone the repo and then prune unused objects:

    $ git clone badrepo goodrepo && cd goodrepo
    $ git gc --prune=all
    
  3. The new repository is clean. git fsck returns no errors.




回答2:


You can find a perfectly working example on git-scm.com. As already mentioned by torek, it uses git filter-branch to rewrite all the history affected by your problem.

You will have to change it a bit:

$ git filter-branch --commit-filter '
    if [ "$GIT_AUTHOR_NAME" = "name_and_email" ];
    then
            GIT_AUTHOR_NAME="name";
            GIT_AUTHOR_EMAIL="email";
            git commit-tree "$@";
    else
            git commit-tree "$@";
    fi' HEAD

Not sure weather the $GIT_AUTHOR_NAME will work on the invalid commits, but if it does the above command should do the trick for one author.


If all your commits have the problem, you can skip the if thing and use a regex or something like that to automatically find the border between name and email. That way you can do it completely automatic for all authors.



来源:https://stackoverflow.com/questions/21971941/invalid-author-committer-line-missing-space-before-email

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!