0

I fetch my latest git log message via $commitMessage = git log -1 --pretty=full 2>&1. What confuses me is that $commitMessage.contains("`n") returns False, but there are clearly line breaks in $commitMessage.

How can I replace all linebreaks in $commitMessage?

Example content of $commitMessage:

commit ca82a6dff817ec66f44342007202690a93763949
Author: Scott Chacon <[email protected]>
Date:   Mon Mar 17 21:52:11 2008 -0700

    changed the version number

Thanks

1
  • 1
    $commitMessage is an array of strings, not a single multi-line string. You can concatenate them with the -join operator Commented Jul 19, 2016 at 9:55

1 Answer 1

5

It's likely that $commitMessage is actually an array of strings. To find out, use the .GetType() method like so,

$commitMessage.GetType()

This will tell what kind of object you are working with. To join an array of strings, use the -join operator like so,

# A demo array of strings
$commitMessage = @()
$commitMessage += "commit ca82a6dff817ec66f44342007202690a93763949"
$commitMessage += "Author: Scott Chacon <[email protected]>"
$commitMessage += "Date:   Mon Mar 17 21:52:11 2008 -0700"
$commitMessage
commit ca82a6dff817ec66f44342007202690a93763949
Author: Scott Chacon <[email protected]>
Date:   Mon Mar 17 21:52:11 2008 -0700

# Join the cells with using arbitary separator
$commitMessage -join '|'
commit ca82a6dff817ec66f44342007202690a93763949|Author: Scott Chacon <[email protected]>|Date:   Mon Mar 17 21:52:11 2008 -0700
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.