I need to create a new branch, from the existing branch using the git checkout
and option start-point
but I am not sure how I can determine it properly.
from git log
I need to find a commit which has specific transaction number in the message.
E.g. from git log
..........................................
commit b91a725feea867e371c5488e9fe60ca4cd0e927f
Author: john.smith
Date: Tue Mar 15 11:54:50 2022 0100
Improve error messages for instrument creation
[AccuRev transaction: 20839205]
commit c4d1ebd3da59efa7223876b1de37960f2e6bcbff
Author: john.smith
Date: Fri Mar 11 16:52:04 2022 0100
Added new libraries
[AccuRev transaction: 20829020]
...............................
So for example I need to find the commit which message contains this string (with specific Transaction number value): [AccuRev transaction: 20829020]
So two questions:
- how to get this specific log message from all the
git logs
and how to retrievecommit hash id
for that particular commit? - will it be enough to execute command
git checkout -b branchName commitHashId
to create a new branch from that specific start-point?
Edit: git log --grep
does not provide me with correct result when trying to filter specific ID:
Please look at the example:
git log --grep="[AccuRev transaction: 698102]"
commit f6d975e531b15c14683155a9e3ceca45d6a51854 (HEAD -> SoftBroker)
Author: stefan
Date: Mon Feb 21 10:57:34 2022 0100
SPRs ,,,JIRA Issues SOF-46,SOF-49,SOF-6782,SOF-6784 Promote pom files.
[AccuRev transaction: 20754456]
commit 0ee4ede74e3efe9d98a42ae5a6cb4c2641cd1384
Author: alek
Date: Mon Feb 7 17:08:17 2022 0100
SOF-6707: Account should be pre-selected after user login
[AccuRev transaction: 20706246]
commit 633a0f21584f5578aaac1848255aa850bc95b52a
Author: alek
Date: Mon Feb 7 17:06:18 2022 0100
JIRA Issue increasing version to 2022.1.1 and 2022.Q1.1
[AccuRev transaction: 20706239]
Thanks a lot
CodePudding user response:
To find a revision that has a certain message you do:
git log --grep=whatever-you-need-to-find
That should give you a list of revisions that match the regex that you provided. Then, it is the question about checking out an a branch.
git checkout some-revision-id
does not create a new branch. All git will do is go to that revision and put in on the working tree and you will be working on what is called a detached HEAD.... in other words, you will be working without a branch (perfectly fine... one of the best features that git has... among a big list of great features). If you want to create a branch from that point, you should then run
git checkout -b some-new-branch some-revision-id
Which will create the new branch on that revision and check it out, in a single operation.
CodePudding user response:
Git has revision syntax for simply naming commits by message content.
git checkout -b mynewbranch ':/\[AccuRev transaction: 20829020\]'
with the backslashes needed because [
is a syntax marker in the search- expression language