public void ApplyChanges() { Repository repo; try { repo = new Repository(RepoPath); } catch { DlgMessage.ShowWarning("It looks like there is no valid Git repository at this path anymore. Please use “Browse” to load from another path."); return; } var knownCommits = Commits.ToDictionary(c => c.Hash); var loadedCommits = new HashSet <string>(repo.Commits.Select(c => c.Id.Sha)); if (knownCommits.Count != loadedCommits.Count || knownCommits.Keys.Any(c => !loadedCommits.Contains(c)) || loadedCommits.Any(c => !knownCommits.ContainsKey(c)) || repo.Commits.Any(cl => !knownCommits[cl.Id.Sha].MatchesOriginal(cl))) { DlgMessage.ShowWarning("The repository at this path has changed since it was last loaded. Please use Reload before applying changes."); return; } foreach (var rf in repo.Refs.Where(rf => rf.CanonicalName.StartsWith("refs/original/")).ToList()) { repo.Refs.Remove(rf); } repo.Refs.RewriteHistory(new RewriteHistoryOptions { CommitHeaderRewriter = arg => { var ours = knownCommits[arg.Id.Sha]; return(new CommitRewriteInfo { Author = new Signature(ours.AuthorName, ours.AuthorEmail, ours.AuthorDate), Committer = new Signature(ours.CommitterName, ours.CommitterEmail, ours.CommitterDate), Message = ours.Message }); } }, repo.Commits); InitialLoadRepo(RepoPath); DlgMessage.ShowInfo("Changes applied successfully."); }