Git revert back and append changes

Viewed 26

In multiple script files, certain lines were replaced with new ones. In git it looks like that:

- Write-Host "Something went wrong" -ForegroundColor Red
+ Custom-LoggingFunction "Something went wrong" -ErrorAction Stop

The branch is now dozens of commits ahead.

I would like to have both of the lines now - the Custom-LoggingFunction lines and the ones that were removed - Write-Host ones.

If I simply revert, I will loose all current changes. What would be the most optimal solution in that case?

2 Answers

Do a revert --no-commit

git revert --no-commit whatever

Then work with your IDE to select what you would like to keep when comparing with HEAD... that's what I do in these cases.

Here is one good option if you are working with a good modern IDE such as IntelliJ or XCode. You may choose from the IDE to compare a given script file against an earlier revision having the original Write-Host lines. The diff tool should show you both versions, original and new. From there, you may copy and paste the now deleted lines over to the latest version.

Related