-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsession-commit-main.qmd
49 lines (31 loc) · 1.16 KB
/
session-commit-main.qmd
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
---
title: "Introduction to Git and GitHub"
subtitle: "Session - Commit to main (and undo last commit!)"
---
## Not recommended, but sometimes useful
The `pr_*` functions all relate to Pull Requests but it is possible to commit to main directly
Commit work using
```{r}
gert::git_commit_all("This is a message")
# or
gert::git_add("file.qmd")
gert::git_commit("This is a message")
```
and then use the `Push` button in the Git RStudio pane
## Accidental commits!
If you commit by accident to any branch, but particularly `main`, you can undo the last commit
In fact, you can undo any number of last commits!
This has to be done in the `Terminal` though ($)!
```{bash}
git reset --soft HEAD~1
```
:::{.callout-warning collapse=false appearance='default' icon=true}
## Resetting doesn't delete
Be careful if you are trying to undo something sensitive, a reset is not a deletion
:::
## Moving changes from one branch to another
What if you've made a few changes that you want to keep but committed to `main`?
- In RStudio create a new branch (which will have all the changes)
- Return to `main`
- Use the `terminal` to reset the commits you don't want
## End session