Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pull a specific commit using libgit2sharp

hopefully someone call help. First off, I am pretty new to git, so forgive me if I make some mistakes in explaining my question.

I would like to pull the source code as it exists up to a specific commit using the library using libgit2sharp. So if there is a history of

  1. Commit
  2. Commit
  3. Commit
  4. Commit
  5. Commit
  6. Commit
  7. Commit
  8. Commit
  9. Commit
  10. Commit

I would like to be able to pull the source code for 5, or any other number in that list. None of the source will be tagged so I have to use the commits for the pull. Hopefully someone can help.

I have looked at https://github.com/libgit2/libgit2sharp/wiki/git-pull but it does not appear to let me pass in a sha or commit id.

Edited my question to be clear I am using the library.

like image 491
SpaceGhost440 Avatar asked Feb 14 '20 19:02

SpaceGhost440


1 Answers

So another dev answered the question. All I needed to do was a clone, then a checkout against the commit I wanted to reset to. This seems to work the way I wanted.

//clone the master 
dir = Path.Combine(localPath, "Target");
Directory.CreateDirectory(dir);
Repository.Clone(tfsUri, dir);

//reset master to the base of the branch
using (var localRepo = new Repository(dir))
{
    var localCommit = localRepo.Lookup<Commit>(priorCommitId);
    Commands.Checkout(localRepo, localCommit);
}

Not sure if this is what you meant @0andriy, but your comment was a bit confusing.

like image 97
SpaceGhost440 Avatar answered Nov 19 '22 09:11

SpaceGhost440