Skip to content
vpfau edited this page Oct 24, 2018 · 1 revision

git-reset

Undo a dirtied index

Git

$ git reset

LibGit2Sharp

using (var repo = new Repository("path/to/your/repo"))
{
    Commit currentCommit = repo.Head.Tip;
    repo.Reset(ResetMode.Mixed, currentCommit);
}

Undo the last commit

Git

$ git reset --soft HEAD^

LibGit2Sharp

using (var repo = new Repository("path/to/your/repo"))
{
    Commit previousCommit = repo.Head.Commits.ElementAt(1);
    repo.Reset(ResetMode.Soft, previousCommit);
}

Permanently undo commits not pushed to remote

Git

$ git reset --hard origin/master

LibGit2Sharp

using (var repo = new Repository("path/to/your/repo"))
{
    Branch originMaster = repo.Branches["origin/master"];
    repo.Reset(ResetMode.Hard, originMaster.Tip);
}