Can I undo the formatting style changes that Black makes to my Python code?

Some text editors and IDEs like Pycharm allow you to simply hit cmd+Z (or whatever the undo command is within the editor) to revert back to the state before autoformatting. Also, before autoformatting you can test out what the results will be using Black Playground.


Using the --diff flag, it is possible to pipe the output to patch which then emits to stdout. A one-line shellscript can be used as a wrapper, where $1 is the file that is being formatted:

black --quiet --diff "$1" | patch --quiet -o - "$1"


No it does not. It does nothing more, but reformat the files it has been passed. It's simply a well behaved Unix tool and it expects you to handle your own version control.

Its --diff option is the best you can get:

--diff

Don't write the files back, just output a diff for each file on stdout.

Source: https://github.com/psf/black#command-line-options