I've got a commit "Test 123" and I need to check if this commit was pushed or not.
If not - I need to check the next logic:
If(The last commit with message "Test 123" wasn't pushed ){ then..... git push }
Please help how to check it correctly in PowerShell?
CodePudding user response:
Something like this should work:
# Depending on your workflow, possibly fetch first here.
$commitTitle = "Test 123"
$logOutput = git log '@{u}..@' --pretty=format:'%s'
if ($logOutput.contains($commitTitle))
{
# do something, in your example, maybe git push
}
Explanation: the git log
command says, show me all of my commits on my current branch that are not on the upstream yet. (Note the order here matters when using the 2-dot syntax. If you flip it and used @..@{u}
you'd get all the commits that are on the upstream branch that aren't on your local branch yet.) Once you have all of the commits, format them to only output the commit subjects (sometimes called "titles" which is the first line of the commit message1). Then if any of those commit subjects are equal to the $commitTitle
variable, you found it.
1 Note a commit subject is the first line of a commit message, but only if a multi-line commit message has a blank line after the first line. If someone improperly formats a commit message to have multiple lines without a blank line after the first line, then all lines will be considered part of the subject.
CodePudding user response:
Here I read:
Branches should be named something that describes the purpose of the branch. Note that branch names can’t contain whitespace: new-feature and new_feature are valid branch names, but new feature is not.
You are using Test 123
instead of something like Test_123
. Try another name.