Skip to content

Commit 12f3267

Browse files
committed
docs: add example to the rebase manual page
1 parent 6a7614d commit 12f3267

2 files changed

Lines changed: 117 additions & 15 deletions

File tree

R/rebase.R

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@
33
#' @description
44
#' * `git_cherry_pick()` applies the changes from a given commit (from another branch)
55
#' onto the current branch.
6-
#' *`git_rebase_commit()` resets the branch to the state of another branch (upstream)
6+
#'
7+
#' * `git_rebase_commit()` resets the branch to the state of another branch (upstream)
78
#' and then re-applies your local changes by cherry-picking each of your local
89
#' commits onto the upstream commit history.
9-
#' *`git_rebase_list()` shows your local commits that are missing from the `upstream`
10+
#'
11+
#' * `git_rebase_list()` shows your local commits that are missing from the `upstream`
1012
#' history, and if they conflict with upstream changes.
1113
#'
14+
#' * `git_ahead_behind()` returns a list containing the number of commits ahead and behind
15+
#' comparing `upstream` to `ref`,
16+
#' and the HEAD for respectively the `ref` and `upstream`.
17+
#'
1218
#'
1319
#' @details
1420
#' To find if your local commits are missing from `upstream`,
@@ -20,6 +26,51 @@
2026
#' "rebasing" state. If conflicts arise, `git_rebase_commit()` will raise an error
2127
#' without making changes.
2228
#'
29+
#' @examplesIf interactive()
30+
#' # Cherry-picking
31+
#' repo <- tempfile()
32+
#' gert::git_init(path = repo)
33+
#' writeLines("hello", file.path(repo, 'hello.txt'))
34+
#' git_add('hello.txt', repo = repo)
35+
#' first_commit <- git_commit(
36+
#' "First commit",
37+
#' author = "Jane Doe <jane@example.com>",
38+
#' repo = repo
39+
#' )
40+
#' # Create a feature branch with a new commit
41+
#' mainbranch <- gert::git_branch(repo = repo)
42+
#' git_branch_create('feature', repo = repo)
43+
#' write.csv(mtcars, file.path(repo, 'mtcars.csv'))
44+
#' git_add('mtcars.csv', repo = repo)
45+
#' commit <- git_commit(
46+
#' "Added mtcars.csv file",
47+
#' author = "Jane Doe <jane@example.com>",
48+
#' repo = repo
49+
#' )
50+
#' # Cherry pick the commit onto main
51+
#' git_branch_switch(mainbranch, repo = repo)
52+
#' git_log(repo = repo)
53+
#' git_cherry_pick(commit, repo = repo)
54+
#' git_log(repo = repo)
55+
#'
56+
#' # Clean up
57+
#' unlink(repo, recursive = TRUE)
58+
#'
59+
#' # git ahead/behind and git_rebase_list
60+
#' repo <- file.path(tempdir(), 'gert')
61+
#' if (!file.exists(repo)) {
62+
#' git_clone('https://github.com/r-lib/gert', path = repo)
63+
#'}
64+
#' # Drop some commits, and fast-forward them back
65+
#' git_reset_hard('HEAD~5', repo = repo)
66+
#' file.create(file.path(repo, "bla"))
67+
#' git_add("bla", repo = repo)
68+
#' git_commit("add bla", repo = repo)
69+
#' git_ahead_behind(repo = repo)
70+
#' git_rebase_list(repo = repo)
71+
#'
72+
#' # Clean up
73+
#' unlink(repo, recursive = TRUE)
2374
#' @export
2475
#' @rdname git_rebase
2576
#' @name git_rebase

man/git_rebase.Rd

Lines changed: 64 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)