-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path06_troubleshooting.Rmd
93 lines (64 loc) · 1.82 KB
/
06_troubleshooting.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# Troubleshooting Problems and Fixing Mistakes
## Undoing Things
Merge conflicts are some of the most common hiccups you'll encounter with Git,
but there are a few others. We'll discuss them briefly here.
If you forget to add a file to a commit, or you mess up your commit message,
you can redo the commit. Stage the files you forgot and commit again using the
`--amend` flag
```
$ git commit --amend
```
If you decide you aren't ready to commit a staged file, you can un-stage it
with
```
$ git reset HEAD <file>
```
or with
```
$ git restore --staged <file>
```
You can reset all uncommitted changes made to a file with
```
$ git checkout -- <file>
```
## Hard Resets
Here's how you roll everything in a directory back to the last commit
```
$ git reset --hard HEAD
```
Rolling everything back to the next to last commit (the commit before the
`HEAD` commit)
```
$ git reset --hard HEAD^
```
Rolling everything back to two commits before `HEAD`
```
$ git reset --hard HEAD^2
```
And finally, rolling everything back to an identified commit using a `hash`
from the log
```
$ git reset --hard <hash>
```
To reset everything back to an earlier commit and make sure that the `HEAD`
pointer is pointing to the newly reset `HEAD`, do the following
```
$ git reset --hard <hash>
$ git reset --soft HEAD@{1}
```
## Deleting Files
If you'd like to delete a file from Git, use
```
$ git rm <file>
```
Note that this will also delete the file from your file system. If you want to
keep the file on your computer, use
```
$ git rm --cached <file>
```
Make a commit to the repository and Git will delete the file.
And with all that, you're ready to start using Git in your own projects!
::: {.exercise #ex4 name="Reset main branch and merge"}
Move the `main` branch back by one commit and then merge the second branch into
that commit.
:::