void undoLocalChanges() {

        workspaceProvider.synchronizedOperation(new Callable<Void>() {
            @Override
            public Void call() {
                try {
                    LOGGER.info("Undo local changes due to failure of git operations");
                    try {
                        git.rebase().setOperation(RebaseCommand.Operation.ABORT).call();
                    } catch (WrongRepositoryStateException e) {
                        // ignore rebasing exception when in wrong state
                    }
                    final String remoteBranch = Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + '/' + git.getRepository().getBranch();
                    git.reset().setMode(ResetType.HARD).setRef(remoteBranch).call();
                    git.clean().setCleanDirectories(true).call();
                    try {
                        final ObjectId head = git.getRepository().resolve(Constants.HEAD);
                        LOGGER.info("Undo local changes completed. HEAD is " + head.getName());
                    } catch (final Exception e) {
                        LOGGER.warn("Failed to fetch HEAD", e);
                    }
                } catch (final Exception e) {
                    LOGGER.error("Unable to undo changes", e);
                }
                return null;
            }
        });
    }
void undoLocalChanges ( ) { workspaceProvider . synchronizedOperation ( new Callable < Void > ( ) { @ Override public Void call ( ) { try { LOGGER . info ( "Undo local changes due to failure of git operations" ) ; try { git . rebase ( ) . setOperation ( RebaseCommand . Operation . ABORT ) . call ( ) ; } catch ( WrongRepositoryStateException e ) { } final String remoteBranch = Constants . R_REMOTES + Constants . DEFAULT_REMOTE_NAME + '/' + git . getRepository ( ) . getBranch ( ) ; git . reset ( ) . setMode ( ResetType . HARD ) . setRef ( remoteBranch ) . call ( ) ; git . clean ( ) . setCleanDirectories ( true ) . call ( ) ; try { final ObjectId head = git . getRepository ( ) . resolve ( Constants . HEAD ) ; LOGGER . info ( "Undo local changes completed. HEAD is " + head . getName ( ) ) ; } catch ( final Exception e ) { LOGGER . warn ( "Failed to fetch HEAD" , e ) ; } } catch ( final Exception e ) { LOGGER . error ( "Unable to undo changes" , e ) ; } return null ; } } ) ; }
Performs git reset --hard and git clean -fd to undo local changes.