From fcef4406d7db2325da2efbfdba518d9e3c1d632c Mon Sep 17 00:00:00 2001 From: konradpa Date: Tue, 23 Jul 2024 15:50:08 +0200 Subject: [PATCH 1/4] add Rstudio instructions --- chapters/first-steps-git.qmd | 106 +++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/chapters/first-steps-git.qmd b/chapters/first-steps-git.qmd index c05fe6ef..b1817eec 100644 --- a/chapters/first-steps-git.qmd +++ b/chapters/first-steps-git.qmd @@ -210,6 +210,10 @@ As further introduction to the basic workflow of Git you can check out the last ### Staging +::: {.panel-tabset} + +#### Command Line {{< fa terminal >}} + You can use `git add` to place new or modified files in the staging area. The staging area acts as a space for gathering changes you plan to commit shortly. It bridges between your modified files and the next commit. @@ -258,6 +262,25 @@ Adds modifications and deletions, but not new files. Ignores errors when adding files, allowing the command to continue even if some files cannot be added. ::: +#### RStudio {{< fa brands r-project >}} + +In RStudio, you can use the built-in Git interface to stage your changes without using the command line: + +1. **Open the Git tab**: +In RStudio, go to the top right pane where you can find the "Git" tab. +Click on it to open the Git interface. + +2. **View changed files**: +Under the Git tab, you will see a list of files that have been changed or are new. +These are equivalent to the files that you would see if you ran git status in the command line. + +3. **Stage specific files**: +To stage a specific file, check the box next to the file you want to stage. +This action is equivalent to running `git add filename.txt` in the command line. +The files you check are now in the staging area and ready to be committed. + +::: + ### Committing Now that the changes to your file(s) are staged, you are ready to **create a commit**. @@ -270,6 +293,10 @@ Commits are like milestones in your project's history, and they allow you to kee You can go back to any commit to see what your project looked like at that point or even undo changes if needed. Commits help you manage and document the history of your project. +::: {.panel-tabset} + +#### Command Line {{< fa terminal >}} + To create a commit, use the `git commit` command followed by the flag `-m` and a commit message *in quotes* that describes the changes you made. The commit message should be short yet informative, providing enough detail to understand the purpose of the commit. If you just use `git commit` without adding a commit massage, the text editor of [your choosing](setup.qmd), opens up and lets you type in a commit message. @@ -295,6 +322,44 @@ They allow you to track the history of your project and easily revert changes if You can use the same workflow of `git add` and `git commit` for every file you add or make changes in. +#### RStudio {{< fa brands r-project >}} + +You can also create commits using the Git Interface in RStudio: + +1. **Stage your changes**: +Before committing, make sure you have staged the changes you want to include in the commit. +You can do this by checking the boxes next to the files in the "Git" tab, as explained in the previous instructions. + +2. **Open the commit dialog**: +Once you have staged your change(s), click the “Commit” button on top of the Git tab. +This will open a new window where you can enter your commit message. + +3. **Enter a commit message**: +In the commit dialog window, you will see a text box where you can type your commit message. +The commit message should be short yet informative, providing enough detail to understand the purpose of the commit. +For example, you might type: `Add filename.txt file` + +4. **Review the staged changes**: +Below the commit message box, you will see a list of the changes that are staged for the commit. +You can review these changes to make sure everything you want to commit is included. + +5. **Create the commit**: + +After entering your commit message and reviewing the staged changes, click the “Commit” button at the bottom of the commit dialog window. This will create the commit with the specified message. + +6. **View the output**: +After committing, you will see output in the Git tab similar to the following: + +``` +[main (root-commit) e9ea807] Add filename.txt file + 1 file changed, 0 insertions(+), 0 deletions(-) + create mode 100644 filename.txt +``` +You have now successfully created a commit in the Git repository! + +::: + + #### Rock climbing analogy > Using a Git commit is like using anchors and other protection when climbing. @@ -359,6 +424,10 @@ It allows you to add new changes to the previous commit or modify its commit mes ### Logging commits +::: {.panel-tabset} + +#### Command Line {{< fa terminal >}} + To look at the history of your past commits, you can use the `git log` command. ```{zsh filename="Code"} @@ -408,6 +477,24 @@ Similarly, `git checkout HEAD~1` will move `HEAD` back one commit as a way to lo ::: +#### RStudio {{< fa brands r-project >}} + +To look at the history of your past commits using Git in RStudio, follow these steps: + +1. **Open the Git tab**: +In RStudio, navigate to the top right pane where you can find the "Git" tab. Click on it to open the Git interface. + +2. **View commit history**: +In the Git tab, click on the "History" button. +(The button looks like a little clock.) +This will open a new window displaying the commit history for your project. + +3. **Review commit details**: +The commit history window will show a list of past commits. +Each commit will display details such as the commit hash, author, date, and commit message, similar to the output of the git log command in the terminal. +You can also choose to only look at commits which include changes to a specific directory or file. +::: + ### Comparing versions Another very handy feature is the `git diff` command. @@ -552,6 +639,10 @@ Some examples for commit messages, which stick to the etiquette: ### Amending a commit +::: {.panel-tabset} + +#### Command Line {{< fa terminal >}} + The `git commit --amend` command is used to modify (or "amend") your most recent Git commit in your repository. It allows you to edit the commit message, add more changes to the commit, or simply adjust the last commit without creating a new commit. This flag can be useful if you forgot to include something in your last commit, made a typo or want to change your commit message. @@ -572,6 +663,21 @@ git commit --amend --no-edit The `--no-edit` flag, lets you keep the commit message of your most recent commit. +#### RStudio {{< fa brands r-project >}} + +In RStudio, you can also amend your most recent commit without needing to use the command line_ + +1. **Stage your new changes**: +In the "Git" tab, check the boxes next to the files you want to include in the amended commit. + +2. **Amend the commit**: +After staging the new changes, click the "Commit" button. +In the commit dialog window, you will see an option to "Amend previous Commit". +Ensure the "Amend previous Commit" option is selected. +You can also change the commit message here. +Click the "Commit" button to finalize the changes +::: + #### The repeated `--amend` workflow Let's consider the following part of the [rock climbing analogy](#rock-climbing-analogy) for commits again: From 4116aa82dba60018e1a5cdd137258492e89848c5 Mon Sep 17 00:00:00 2001 From: konradpa Date: Mon, 29 Jul 2024 16:34:54 +0200 Subject: [PATCH 2/4] add rstudio doc to branches chapter --- chapters/branches.qmd | 51 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/chapters/branches.qmd b/chapters/branches.qmd index 5d7650de..dae60e46 100644 --- a/chapters/branches.qmd +++ b/chapters/branches.qmd @@ -81,6 +81,10 @@ nothing to commit, working tree clean ## Creating a new branch +::: {.panel-tabset} + +#### Command Line {{< fa terminal >}} + To create a new branch, use `git branch` followed by a branch name. For example, to create a new branch called `feature` run the following command: @@ -126,8 +130,34 @@ For example, `git branch -c existing-branch new-branch` `-v` or `--verbose`: Shows more information when listing branches, including the last commit message. ::: +#### RStudio {{< fa brands r-project >}} + +To create a new branch using the RStudio GUI, follow these steps: + +1. **Access the Git Pane**: +Locate the Git pane, usually found in the top-right corner of the RStudio interface. + +2. **Create a New Branch**: +On the top of the pane, on the left side to the name of the branch you are currently on, there is a purple branch symbol. +Click on it. + +3. **Name the New Branch**: +A prompt will appear asking you to name the new branch. +Enter the desired name for your new branch, for example, `feature`. +You can also choose to setup a remote branch with the same name. + +4. **Create and Switch to the New Branch**: +After naming the new branch, click "Create" to create the branch. +RStudio will create the new branch and automatically switch to it. +You should see a confirmation message indicating the successful creation and switch to the new branch. +::: + ## Switching branches +::: {.panel-tabset} + +#### Command Line {{< fa terminal >}} + To switch to another branch, you can use `git checkout` or `git switch`. For example, enter the following command to switch to the newly created `feature` branch: @@ -161,6 +191,27 @@ It simplifies the branch-switching process and provides clearer feedback in case It can be used for branch switching, but it may have some ambiguity in its syntax, especially when used for other purposes. ::: +#### RStudio {{< fa brands r-project >}} + +To switch to another branch using the RStudio GUI, follow these steps: + +1. **Access the Git Pane**: +Locate the Git pane, usually found in the top-right corner of the RStudio interface. + +2. **View Branches**: +In the Git pane, you should see the name of the branch you are currently on. +E.g. "Main" or "Master". +Click on the name of your current branch. +This will open a dialog showing the current branch and available branches. + +3. **Switch to Another Branch**: +In the branches dialog, you will see a list of branches. Locate the branch you want to switch to, for example, feature. +Click on the branch name (e.g., feature) to select it. +After clicking on it, RStudio will switch to the selected branch. +You should see a confirmation message indicating the successful switch, similar to the command line output: Switched to branch 'feature' + +::: + ### Switching branches with uncommitted changes ::: {.callout-caution collapse="false" appearance="simple"} From b6d45a2315ee6369ccd28a9ad3e63951a2d032ed Mon Sep 17 00:00:00 2001 From: Lennart Wittkuhn Date: Tue, 27 Aug 2024 09:34:57 +0200 Subject: [PATCH 3/4] Remove duplicate explanation of staging area --- chapters/first-steps-git.qmd | 2 -- 1 file changed, 2 deletions(-) diff --git a/chapters/first-steps-git.qmd b/chapters/first-steps-git.qmd index e559050d..eedc4e72 100644 --- a/chapters/first-steps-git.qmd +++ b/chapters/first-steps-git.qmd @@ -214,8 +214,6 @@ As further introduction to the basic workflow of Git you can check out the last #### Command Line {{< fa terminal >}} You can use `git add` to place new or modified files in the staging area. -The staging area acts as a space for gathering changes you plan to commit shortly. -It bridges between your modified files and the next commit. For example, you can stage a specific file like this: From f86f6ed54abed124b65f49d793e4668ecfe5dbad Mon Sep 17 00:00:00 2001 From: konradpa Date: Tue, 10 Sep 2024 14:04:20 +0200 Subject: [PATCH 4/4] add images to rstudio sections --- chapters/branches.qmd | 5 +++++ chapters/first-steps-git.qmd | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/chapters/branches.qmd b/chapters/branches.qmd index dae60e46..cc262dbf 100644 --- a/chapters/branches.qmd +++ b/chapters/branches.qmd @@ -150,6 +150,9 @@ You can also choose to setup a remote branch with the same name. After naming the new branch, click "Create" to create the branch. RStudio will create the new branch and automatically switch to it. You should see a confirmation message indicating the successful creation and switch to the new branch. + +![Creating a branch using Rstudio](../static/rstudio_newbranch.png){#fig-rstudio_newbranch} + ::: ## Switching branches @@ -210,6 +213,8 @@ Click on the branch name (e.g., feature) to select it. After clicking on it, RStudio will switch to the selected branch. You should see a confirmation message indicating the successful switch, similar to the command line output: Switched to branch 'feature' +![Switching branches using Rstudio](../static/rstudio_switchbranch.png){#fig-rstudio_switchbranch} + ::: ### Switching branches with uncommitted changes diff --git a/chapters/first-steps-git.qmd b/chapters/first-steps-git.qmd index eedc4e72..874b637d 100644 --- a/chapters/first-steps-git.qmd +++ b/chapters/first-steps-git.qmd @@ -276,6 +276,8 @@ To stage a specific file, check the box next to the file you want to stage. This action is equivalent to running `git add filename.txt` in the command line. The files you check are now in the staging area and ready to be committed. +![Staging changes using Rstudio](../static/rstudio_staging.png){#fig-rstudio_staging} + ::: ### Committing @@ -354,6 +356,9 @@ After committing, you will see output in the Git tab similar to the following: ``` You have now successfully created a commit in the Git repository! +![Committing staged changes using Rstudio](../static/rstudio_committing.png){#fig-rstudio_committing} + + ::: @@ -489,6 +494,10 @@ This will open a new window displaying the commit history for your project. The commit history window will show a list of past commits. Each commit will display details such as the commit hash, author, date, and commit message, similar to the output of the git log command in the terminal. You can also choose to only look at commits which include changes to a specific directory or file. + +![Committing staged changes using Rstudio](../static/rstudio_log.png){#fig-rstudio_log} + + ::: ### Comparing versions