git_uncommit(ask = TRUE, repo = ".")
when
attribute holds the commit time as
POSIXct
. An excerpt of the commit message is in the msg_start
attribute.
git_uncommit()
will not change your files. It just reverses the act of
making the most recent Git commit. Even the staged / unstaged status of your
modifications is preserved. When might you use this? To undo the last commit
so you can stage different changes or files and/or redo your commit, but with
a better message. Note that git_amend()
might be a more
efficient way to do that.When might you NOT want to use this? If you have already pushed the most recent commit to a remote. It could still be OK if you're sure no one else has pulled. But be prepared to force push in this situation.
git_uncommit()
addresses the second most up-voted question on
StackOverflow:
How
to undo last commit(s) in Git?, with over 3.6 million views. It is
equivalent to git reset --soft HEAD^
, i.e. a soft reset to the commit
that is parent to the commit pointed to by current HEAD.
repo <- git_init(tempfile("githug-"))
owd <- setwd(repo)
write("Are these girls real smart or real real lucky?", "max.txt")
git_commit("max.txt",
message = "Brains'll only get you so far and luck always runs out.")
write("Did I hear somebody say \"Peaches\"?", "jimmy.txt")
git_commit("jimmy.txt", message = "That's the code word. I miss you, Peaches.")
git_history() ## see? 2 commits
git_status() ## see? nothing to stage
git_uncommit() ## roll back most recent commit
git_history() ## see? only 1st commit is in history
git_status() ## see? jimmy.txt is a new, staged file
## re-do that 2nd commit but with message in ALL CAPS
git_commit(message = "THAT'S THE CODE WORD. I MISS YOU, PEACHES.")
git_history() ## see? back to 2 commits
setwd(owd)
Run the code above in your browser using DataLab