From 14da9d3e45fa6958343e9199ecf700892ba4a0c8 Mon Sep 17 00:00:00 2001 From: kshyatt Date: Thu, 4 May 2017 21:06:55 -0700 Subject: [PATCH] Add example for checkout --- base/libgit2/libgit2.jl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/base/libgit2/libgit2.jl b/base/libgit2/libgit2.jl index ac7dfa7a1683b..d875be7ec288e 100644 --- a/base/libgit2/libgit2.jl +++ b/base/libgit2/libgit2.jl @@ -458,6 +458,23 @@ Equivalent to `git checkout [-f] --detach `. Checkout the git commit `commit` (a [`GitHash`](@ref) in string form) in `repo`. If `force` is `true`, force the checkout and discard any current changes. Note that this detaches the current HEAD. + +# Example + +```julia +repo = LibGit2.init(repo_path) +open(joinpath(LibGit2.path(repo), "file1"), "w") do f + write(f, "111\n") +end +LibGit2.add!(repo, "file1") +commit_oid = LibGit2.commit(repo, "add file1") +open(joinpath(LibGit2.path(repo), "file1"), "w") do f + write(f, "112\n") +end +# would fail without the force=true +# since there are modifications to the file +LibGit2.checkout!(repo, string(commit_oid), force=true) +``` """ function checkout!(repo::GitRepo, commit::AbstractString = ""; force::Bool = true)