# Buggy code
def checkout_exp(self, rev):
    """Checkout an experiment to the user's workspace."""
    from git.exc import GitCommandError

    from dvc.repo.checkout import _checkout as dvc_checkout

    self._check_baseline(rev)
    self._scm_checkout(rev)

    tmp = tempfile.NamedTemporaryFile(delete=False).name
    self.scm.repo.head.commit.diff("HEAD~1", patch=True, output=tmp)

    dirty = self.repo.scm.is_dirty()
    if dirty:
        logger.debug("Stashing workspace changes.")
        self.repo.scm.repo.git.stash("push")

    try:
        if os.path.getsize(tmp):
            logger.debug("Patching local workspace")
            self.repo.scm.repo.git.apply(tmp, reverse=True)
            need_checkout = True
        else:
            need_checkout = False
    except GitCommandError:
        raise DvcException("failed to apply experiment changes.")
    finally:
        remove(tmp)
        if dirty:
            self._unstash_workspace()

    if need_checkout:
        dvc_checkout(self.repo)


# 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 checkout_exp(self, rev):
    """Checkout an experiment to the user's workspace."""
    from git.exc import GitCommandError

    from dvc.repo.checkout import _checkout as dvc_checkout

    self._check_baseline(rev)
    self._scm_checkout(rev)

    tmp = tempfile.NamedTemporaryFile(delete=False).name
    self.scm.repo.head.commit.diff(
        "HEAD~1", patch=True, full_index=True, binary=True, output=tmp
    )

    dirty = self.repo.scm.is_dirty()
    if dirty:
        logger.debug("Stashing workspace changes.")
        self.repo.scm.repo.git.stash("push", "--include-untracked")

    try:
        if os.path.getsize(tmp):
            logger.debug("Patching local workspace")
            self.repo.scm.repo.git.apply(tmp, reverse=True)
            need_checkout = True
        else:
            need_checkout = False
    except GitCommandError:
        raise DvcException("failed to apply experiment changes.")
    finally:
        remove(tmp)
        if dirty:
            self._unstash_workspace()

    if need_checkout:
        dvc_checkout(self.repo)