PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, July 11, 2022

[FIXED] How to modify the git -commit messages using jenkins?

 July 11, 2022     commit, git, github, jenkins, message     No comments   

Issue

I'm using a Jenkins server to check build & merge on master. Now I want to implement it so that it modifies the commit messages with a custom string. Concrete example : let's say I made 3 commits on a branch ;

commit #3
commit #2
commit #1

What I want to do is change these messages so that they look like

ISSUE-XX commit #3
ISSUE-XX commit #2
ISSUE-XX commit #1

where XX will be completed by the user triggering the jenkins build. Is there any way to do this? I haven't been able to find an answer online so far.

I already thought about implementing git-hooks but that's not exactly what I want and I also thought about automatic rebasing but I don't quite understand it.


Solution

Solved with squashing, using the script below. The solution squashes the last (NUMBER_OF_COMMITS) into a single one given as a Build Parameter and sets a custom commit message, also given as a build parameter.

    ::Rebasing to modify commit messages

    :: Reset the current branch to the commit just before the last 12:
    git reset --hard HEAD~%NUMBER_OF_COMMITS%

    :: HEAD@{1} is where the branch was just before the previous command.
    :: This command sets the state of the index to be as it would just
    :: after a merge from that commit:
    git merge --squash HEAD@{1}

    :: Commit those squashed changes.
    git commit -m "%ISSUE%"


Answered By - Petrut Jianu
Answer Checked By - David Marino (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing