forked from jennybc/happy-git-with-r
-
Notifications
You must be signed in to change notification settings - Fork 0
/
44_prompt-practice-resets.Rmd
37 lines (22 loc) · 1.46 KB
/
44_prompt-practice-resets.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Resetting {#reset}
Practice recovering from mistakes.
Use a repository you've created earlier in the tutorial for this. It only needs to be local, i.e. this does not involve GitHub.
If it's not your most recent commit, seriously consider just letting that go. Just. Let. It. Go.
So you want to undo the last commit?
If "YES UNDO IT COMPLETELY": `git reset --hard HEAD^`. You will lose any changes that were not reflected in the commit-before-last!
If "YES undo the commit, but leave the files in that state (but unstaged)": `git reset HEAD^`. Your files will stay the same but the commit will be undone and nothing will be staged.
If "YES go right back to the moment before I committed": `git reset --soft HEAD^`. Your files will stay the same but the commit will be undone. Even your staged changes will be restored.
**If you just want to fiddle with the most recent commit or its message, you can amend it. You can do this from RStudio!**
* Make the change you want and amend the commit.
* Do you only want to change the commit message?
- Make another small change. Surely you have a typo somewhere? Amend the commit, which gives you the chance to edit the message
To amend from the command line, using an editor to create the message:
``` bash
git commit --amend
```
To amend from the command line, providing the new message:
``` bash
git commit --amend -m "New commit message"
```
Git Reset Demystified:
<https://git-scm.com/book/en/v2/Git-Tools-Reset-Demystified>