We have committed code in bitbucket repo to one of our environments without any branching related to issues in jira. Is it possible to create branches or link those issues or user stories in jira matching with the already committed code for traceability purposes. Thanks
Hi @Ashlee and welcome to the community!
Regarding creating branches:
This depends on how your commit graph looks now and what you want to achieve.
Let's say there 3 commits that you want to link to Jira issues:
Regarding linking Jira issues to existing commits:
It is possible to change the commit messages of the existing commits so that you add the corresponding Jira issue key in these messages (without creating or changing any branches).
Please note though that this process includes rewriting history, which means that the hashes of these commits (and commits after them) will change.
I would also recommend creating a fork of the repo to test the solution I am suggesting below and pushing the changes to the fork first, to inspect if it's in a good state before you push to the existing repo.
The process to change commits messages is the following:
1. If you want to change the commit messages e.g. of the 9th and 10th latest commits, you can run
git rebase -i HEAD~10
This command will display the latest 10 commits in your default text editor.
2. Move to the lines of the commits whose message you want to change, and replace the word pick with the word reword. Leave the other lines as they are, save the changes and close the editor.
3. Then, for each commit that you chose to reword in the previous step, a new text editor window will open.
In there, you can change the commit message of that specific commit and add the Jira issue key, save the changes and close the editor.
4. After you finish this process, you can run a git log to confirm that the commit messages have been changed to include the Jira issue keys.
5. You will need to push these changes with
git push --force <remoteName> <branchName>
since you have rewritten history.
Again, test this by pushing to a fork of the repo first, to inspect if the repo is in a good state after the push.
Make sure that no one has pushed any newer commits to that branch that you don't have locally, as they will get removed if you force push.
If you have any questions, please feel free to let me know.
Kind regards,
Theodora
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.