Search code examples
gitgit-revert

Git revert back and append changes


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?


Solution

  • 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.