# Buggy code
def _stash_exp(self, *args, params: Optional[dict] = None, **kwargs):
    """Stash changes from the current (parent) workspace as an experiment.

    Args:
        params: Optional dictionary of parameter values to be used.
            Values take priority over any parameters specified in the
            user's workspace.
    """
    rev = self.scm.get_rev()

    # patch user's workspace into experiments clone
    tmp = tempfile.NamedTemporaryFile(delete=False).name
    try:
        self.repo.scm.repo.git.diff(patch=True, output=tmp)
        if os.path.getsize(tmp):
            logger.debug("Patching experiment workspace")
            self.scm.repo.git.apply(tmp)
        elif not params:
            # experiment matches original baseline
            raise UnchangedExperimentError(rev)
    finally:
        remove(tmp)

    # update experiment params from command line
    if params:
        self._update_params(params)

    # save additional repro command line arguments
    self._pack_args(*args, **kwargs)

    # save experiment as a stash commit w/message containing baseline rev
    # (stash commits are merge commits and do not contain a parent commit
    # SHA)
    msg = f"{self.STASH_MSG_PREFIX}{rev}"
    self.scm.repo.git.stash("push", "-m", msg)
    return self.scm.resolve_rev("stash@{0}")


# Traceback (git.exc.GitCommandError)
2020-08-24 12:56:57,888 ERROR: failed to apply experiment changes.
------------------------------------------------------------
Traceback (most recent call last):
File "/Users/pmrowla/git/dvc/dvc/repo/experiments/__init__.py", line 529, in checkout_exp
self.repo.scm.repo.git.apply(tmp, reverse=True)
File "/Users/pmrowla/.virtualenvs/dvc/lib/python3.8/site-packages/git/cmd.py", line 542, in <lambda>
return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
File "/Users/pmrowla/.virtualenvs/dvc/lib/python3.8/site-packages/git/cmd.py", line 1005, in _call_process
return self.execute(call, **exec_kwargs)
File "/Users/pmrowla/.virtualenvs/dvc/lib/python3.8/site-packages/git/cmd.py", line 822, in execute
raise GitCommandError(command, status, stderr_value, stdout_value)
git.exc.GitCommandError: Cmd('git') failed due to: exit code(1)
cmdline: git apply --reverse /var/folders/s_/j8cg24s945dcvlh77c677f080000gn/T/tmptqvdsgr5
stderr: 'error: missing binary patch data for 'model.hdf5'
error: binary patch does not apply to 'model.hdf5'
error: model.hdf5: patch does not apply'

# Fixed code
def _stash_exp(self, *args, params: Optional[dict] = None, **kwargs):
    """Stash changes from the current (parent) workspace as an experiment.

    Args:
        params: Optional dictionary of parameter values to be used.
            Values take priority over any parameters specified in the
            user's workspace.
    """
    rev = self.scm.get_rev()

    # patch user's workspace into experiments clone
    tmp = tempfile.NamedTemporaryFile(delete=False).name
    try:
        self.repo.scm.repo.git.diff(
            patch=True, full_index=True, binary=True, output=tmp
        )
        if os.path.getsize(tmp):
            logger.debug("Patching experiment workspace")
            self.scm.repo.git.apply(tmp)
        elif not params:
            # experiment matches original baseline
            raise UnchangedExperimentError(rev)
    finally:
        remove(tmp)

    # update experiment params from command line
    if params:
        self._update_params(params)

    # save additional repro command line arguments
    self._pack_args(*args, **kwargs)

    # save experiment as a stash commit w/message containing baseline rev
    # (stash commits are merge commits and do not contain a parent commit
    # SHA)
    msg = f"{self.STASH_MSG_PREFIX}{rev}"
    self.scm.repo.git.stash("push", "-m", msg)
    return self.scm.resolve_rev("stash@{0}")