Svn2git: Add revision number to git commit title

寵の児 提交于 2019-12-10 23:16:27

问题


I want to add the svn revision to every git commit title, so can I can see every Revision in each commit in the history of our Team Foundation Server.

I already tried editing a commit with "--amend", but this way it just makes a new commit (and the history becomes incorrect). Also I dont wanna edit every commit one by one. Screenshot of what I wanna archieve The Screenshot shows what I did with --ammend.

I'm using svn2git for the Migration.


回答1:


There are pleny tools called svn2git. If you are not using the KDE one from https://github.com/svn-all-fast-export/svn2git. I strongly recommend using that svn2git tool. It is the best I know available out there and it's very flexible in what you can do with its rules files.

You will easily be able to configure it for your layout to get the result you want and expect.

If you are not 100% about the history of your repository, svneverever from http://blog.hartwork.org/?p=763 is a great tool to investigate the history of a SVN repository when migrating it to Git.

With the latest merged pull requests you can even fulfill your request with it. Just get and compile the sources or wait until a new release is done. Then you can use the --add-metadata switch in combination with the --msg-filter switch which is applied after --add-metadata, so in the --msg-filter process you can take the automatically added metadata with the revision number and move or copy it to the end of the first line of the commit message.




回答2:


You can have several options to do it:

  1. Modify the commit message and store the content in your commit message.
  2. Add metadata to the commit.

Modify the commit message

Like you mentioned in your question is you do a git commit --amend its actually a rebase. rebase modify the commit and change the SHA-1.

You wish to avoid it, so you will need to set the message before committing.
Here is why it's happening, since the message is part of the metadata which calculated when generating the SHA-1.


Add metadata to the commit.

If you want to add extra data to the commit after you have committed the nest way is simply to add notes. Notes is not part of the metadata used to generate the SHA-1 so you can add it after the commit was made.

git notes add -m 'Old commit is: xxxxxx'


来源:https://stackoverflow.com/questions/36304658/svn2git-add-revision-number-to-git-commit-title

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