|
3 | 3 | #' @description |
4 | 4 | #' * `git_cherry_pick()` applies the changes from a given commit (from another branch) |
5 | 5 | #' 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) |
7 | 8 | #' and then re-applies your local changes by cherry-picking each of your local |
8 | 9 | #' 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` |
10 | 12 | #' history, and if they conflict with upstream changes. |
11 | 13 | #' |
| 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 | +#' |
12 | 18 | #' |
13 | 19 | #' @details |
14 | 20 | #' To find if your local commits are missing from `upstream`, |
|
20 | 26 | #' "rebasing" state. If conflicts arise, `git_rebase_commit()` will raise an error |
21 | 27 | #' without making changes. |
22 | 28 | #' |
| 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) |
23 | 74 | #' @export |
24 | 75 | #' @rdname git_rebase |
25 | 76 | #' @name git_rebase |
|
0 commit comments