githug (version 0.0.0.9000)

git_unstage: Unstage changes for the next commit.

Description

Remove file modifications from the staging area for the next commit, BUT LEAVE YOUR FILES ALONE. This function is "working directory safe". It will not change your files. It only unstages them. When would you use this? If you've staged changes by mistake and you don't want them in the next commit after all.

Usage

git_unstage(..., all = FALSE, repo = ".")

Arguments

...
One or more paths that will be matched against files with changes that are staged for the next commit. Paths that match will be unstaged, i.e. their changes will not be part of the next commit.
all
Logical, consulted if no paths are given. If TRUE, pre-authorizes the unstaging of all staged files.
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

git_unstage() addresses a popular question on StackOverflow: How to undo 'git add' before commit?, with over 1.3 million views. In terms of command line Git, this reverses git add file.txt. The call git_unstage("file.txt") is equivalent to git reset file.txt, which is short for git reset --mixed HEAD file.txt, i.e. a mixed reset of file.txt to the commit pointed to by current HEAD.

Examples

Run this code
repo <- git_init(tempfile("githug-"))
owd <- setwd(repo)
write("Are these girls real smart or real real lucky?", "max.txt")
git_commit(all = TRUE, message = "first commit")
write("You get what you settle for.", "louise.txt")
git_status()
git_add("louise.txt")
git_status()
git_unstage("louise.txt")
git_status()
setwd(owd)

Run the code above in your browser using DataCamp Workspace