githug (version 0.0.0.9000)

git_file_rename: Rename or move a file and stage both ends

Description

Rename a file and stage both ends of the transaction, i.e. the deletion of the file under its original name and the addition of the file under its new name. You still need to make the commit. If Git recognizes a rename event, then the history of the file will be preserved. This is worth striving for. Maximize the chance of this happy event by making the rename/move a distinct operation that is not muddled up with other changes to the file.

Usage

git_file_rename(from, to, repo = ".")
git_mv(from, to, repo = ".")

Arguments

from
Path to an existing file, relative to the repo working directory
to
The desired new name, relative to the repo working directory
repo
Path to a Git repo. If unspecified, current working directory is checked to see if it is or is inside a Git repo.

Value

Nothing

Details

This is an extremely simple implementation of basic git mv. Why? True git mv is offered neither by libgit2 nor, therefore, by git2r.

Examples

Run this code
repo <- git_init(tempfile("githug-"))
owd <- setwd(repo)
write("Are these girls real smart or real real lucky?", "louise.txt")
git_commit(all = TRUE, message = "filename is all wrong")
git_mv(from = "louise.txt", to = "max.txt")
git_commit(all = TRUE, message = "corrected filename")
git_history()
setwd(owd)

Run the code above in your browser using DataLab