Licensing
-Last updated on 2023-05-08 | +
Last updated on 2024-10-25 | Edit this page
@@ -504,8 +504,9 @@Key Points
LICENSE.txt
file is often used in a repository to indicate
how the contents of the repo may be used by others.
Key Points
"url": "https://swcarpentry.github.io/git-novice/11-licensing.html", "identifier": "https://swcarpentry.github.io/git-novice/11-licensing.html", "dateCreated": "2014-12-04", - "dateModified": "2023-05-08", + "dateModified": "2024-10-25", "datePublished": "2024-10-25" } diff --git a/12-citation.html b/12-citation.html index 9b9fa1ed3a..b565c09508 100644 --- a/12-citation.html +++ b/12-citation.html @@ -418,30 +418,18 @@Objectives
CITATION.txt
that describes how to reference your project;
the one
for Software Carpentry states:
-To reference Software Carpentry in publications, please cite both of the following:
+To reference Software Carpentry in publications, please cite:
-Greg Wilson: "Software Carpentry: Getting Scientists to Write Better
-Code by Making Them More Productive". Computing in Science &
-Engineering, Nov-Dec 2006.
+Greg Wilson: "Software Carpentry: Lessons Learned". F1000Research,
+2016, 3:62 (doi: 10.12688/f1000research.3-62.v2).
-Greg Wilson: "Software Carpentry: Lessons Learned". arXiv:1307.5448,
-July 2013.
-
-@article{wilson-software-carpentry-2006,
- author = {Greg Wilson},
- title = {Software Carpentry: Getting Scientists to Write Better Code by Making Them More Productive},
- journal = {Computing in Science \& Engineering},
- month = {November--December},
- year = {2006},
-}
-
-@online{wilson-software-carpentry-2013,
+@online{wilson-software-carpentry-2016,
author = {Greg Wilson},
title = {Software Carpentry: Lessons Learned},
- version = {1},
- date = {2013-07-20},
- eprinttype = {arxiv},
- eprint = {1307.5448}
+ version = {2},
+ date = {2016-01-28},
+ url = {http://f1000research.com/articles/3-62/v2},
+ doi = {10.12688/f1000research.3-62.v2}
}
More detailed advice, and other ways to make your code citable can be
found at
diff --git a/13-hosting.html b/13-hosting.html
index 2a70a4401d..d2e70cf8d5 100644
--- a/13-hosting.html
+++ b/13-hosting.html
@@ -414,17 +414,18 @@ Objectives
The second big question for groups that want to open up their work is -where to host their code and data. One option is for the lab, the -department, or the university to provide a server, manage accounts and -backups, and so on. The main benefit of this is that it clarifies who -owns what, which is particularly important if any of the material is -sensitive (i.e., relates to experiments involving human subjects or may -be used in a patent application). The main drawbacks are the cost of -providing the service and its longevity: a scientist who has spent ten -years collecting data would like to be sure that data will still be -available ten years from now, but that’s well beyond the lifespan of -most of the grants that fund academic infrastructure.
+After choosing a license, another big +question for groups that want to open up their work is where to host +their code and data. One option is for the lab, the department, or the +university to provide a server, manage accounts and backups, and so on. +The main benefit of this is that it clarifies who owns what, which is +particularly important if any of the material is sensitive (i.e., +relates to experiments involving human subjects or may be used in a +patent application). The main drawbacks are the cost of providing the +service and its longevity: a scientist who has spent ten years +collecting data would like to be sure that data will still be available +ten years from now, but that’s well beyond the lifespan of most of the +grants that fund academic infrastructure.
Another option is to purchase a domain and pay an Internet service provider (ISP) to host it. This gives the individual or group more control, and sidesteps problems that can arise when moving from one diff --git a/14-supplemental-rstudio.html b/14-supplemental-rstudio.html index e5a8d8f864..c980a31f0e 100644 --- a/14-supplemental-rstudio.html +++ b/14-supplemental-rstudio.html @@ -548,7 +548,7 @@
Solution to Challenge
-This can be done in Rstudio:
OUTPUT<
the project, including the tracked files and sub-directories located
within the project’s directory. If we ever delete the .git
subdirectory, we will lose the project’s history.
-
Next, we will change the default branch to be called
-main
. This might be the default branch depending on your
-settings and version of git. See the setup episode for
-more information on this change.
OUTPUT -
-Switched to a new branch 'main'
-We can now start using one of the most important git commands, which
is particularly helpful to beginners. git status
tells us
the status of our project, and better, a list of changes in the project
and options on what to do with those changes. We can use it as often as
we want, whenever we want to understand what is going on.
OUTPUT
@@ -1070,16 +1056,16 @@ Places to Create Git Repositories
desserts specifically. Alfredo creates a desserts
project
inside his recipes
project with the following sequence of
commands:
-
+
BASH
-$ cd ~/Desktop # return to Desktop directory
-$ cd recipes # go into recipes directory, which is already a Git repository
-$ ls -a # ensure the .git subdirectory is still present in the recipes directory
-$ mkdir desserts # make a sub-directory recipes/desserts
-$ cd desserts # go into desserts subdirectory
-$ git init # make the desserts subdirectory a Git repository
-$ ls -a # ensure the .git subdirectory is present indicating we have created a new Git repository
+$ cd ~/Desktop # return to Desktop directory
+$ cd recipes # go into recipes directory, which is already a Git repository
+$ ls -a # ensure the .git subdirectory is still present in the recipes directory
+$ mkdir desserts # make a sub-directory recipes/desserts
+$ cd desserts # go into desserts subdirectory
+$ git init # make the desserts subdirectory a Git repository
+$ ls -a # ensure the .git subdirectory is present indicating we have created a new Git repository
Is the git init
command, run inside the
desserts
subdirectory, required for tracking files stored
@@ -1092,7 +1078,7 @@
BASH
Show me the solution
-
+
No. Alfredo does not need to make the desserts
subdirectory a Git repository because the recipes
@@ -1108,10 +1094,10 @@
Show me the solution
in the directory, check the output of git status
. If it
looks like the following, you are good to go to create a new repository
as shown above:
-
+
OUTPUT
@@ -1141,7 +1127,7 @@ Correcting git init
Mistakes
-
+
Background
@@ -1150,10 +1136,10 @@ Background
+
Similarly a directory can be removed using
rm -r dirname
. If the files or folder being removed in this
@@ -1167,10 +1153,10 @@
Solution
+
But be careful! Running this command in the wrong directory will
remove the entire Git history of a project you might want to keep. In
@@ -1277,7 +1263,7 @@
OUTPUT<
guacamole.md
-guacamole.md
contains a single line, which we can see by
+
guacamole.md
contains three lines, which we can see by
running:
BASH
@@ -1458,7 +1444,7 @@ OUTPUT<
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
- (use "git checkout -- <file>..." to discard changes in working directory)
+ (use "git restore <file>..." to discard changes in working directory)
modified: guacamole.md
@@ -1523,7 +1509,7 @@ OUTPUT<
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
- (use "git checkout -- <file>..." to discard changes in working directory)
+ (use "git restore <file>..." to discard changes in working directory)
modified: guacamole.md
@@ -1880,7 +1866,7 @@ Choosing a Commit Message
-
+
Answer 1 is not descriptive enough, and the purpose of the commit is
unclear; and answer 2 is redundant to using “git diff” to see what
@@ -1931,7 +1917,7 @@
BASH
Show me the solution
-
+
- Would only create a commit if files have already been staged.
@@ -1970,7 +1956,7 @@ Committing Multiple Files
-
+
First we make our changes to the guacamole.md
and
groceries.md
files:
@@ -2061,7 +2047,7 @@
-
+
If needed, move out of the recipes
folder:
@@ -2274,10 +2260,10 @@ OUTPUT<
HEAD~1
means “the previous commit”, while
HEAD~123
goes back 123 commits from where we are now.
We can also refer to commits using those long strings of digits and
-letters that git log
displays. These are unique IDs for the
-changes, and “unique” really does mean unique: every change to any set
-of files on any computer has a unique 40-character identifier. Our first
-commit was given the ID
+letters that both git log
and git show
+display. These are unique IDs for the changes, and “unique” really does
+mean unique: every change to any set of files on any computer has a
+unique 40-character identifier. Our first commit was given the ID
f22b25e3233b4645dabd0d81e651fe074bd8e73b
, so let’s try
this:
@@ -2317,7 +2303,7 @@ OUTPUT<
--- a/guacamole.md
+++ b/guacamole.md
@@ -1,3 +1,7 @@
- # Gucamole
+ # Guacamole
## Ingredients
+* avocado
+* lime
@@ -2342,18 +2328,17 @@ OUTPUT<
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
- (use "git checkout -- <file>..." to discard changes in working directory)
-
+ (use "git restore <file>..." to discard changes in working directory)
modified: guacamole.md
no changes added to commit (use "git add" and/or "git commit -a")
We can put things back the way they were by using
-git checkout
:
+git restore
:
@@ -2366,15 +2351,15 @@ OUTPUT<
* salt
## Instructions
-As you might guess from its name, git checkout
checks
-out (i.e., restores) an old version of a file. In this case, we’re
-telling Git that we want to recover the version of the file recorded in
-HEAD
, which is the last saved commit. If we want to go back
-even further, we can use a commit identifier instead:
+As you might guess from its name, git restore
restores
+an old version of a file. By default, it recovers the version of the
+file recorded in HEAD
, which is the last saved commit. If
+we want to go back even further, we can use a commit identifier instead,
+using -s
option:
BASH
@@ -2397,97 +2382,44 @@ BASHOUTPUT
On branch main
-Changes to be committed:
- (use "git reset HEAD <file>..." to unstage)
-
+Changes not staged for commit:
+ (use "git add <file>..." to update what will be committed)
+ (use "git restore <file>..." to discard changes in working directory)
modified: guacamole.md
+
+no changes added to commit (use "git add" and/or "git commit -a")
-Notice that the changes are currently in the staging area. Again, we
-can put things back the way they were by using
-git checkout
:
+Notice that the changes are not currently in the staging area, and
+have not been committed. If we wished, we can put things back the way
+they were at the last commit by using git restore
to
+overwrite the working copy with the last committed version:
-
-
-
-
-
-Don’t Lose Your HEAD
-
-Above we used
-
-to revert guacamole.md
to its state after the commit
-f22b25e
. But be careful! The command checkout
-has other important functionalities and Git will misunderstand your
-intentions if you are not accurate with the typing. For example, if you
-forget guacamole.md
in the previous command.
-
-ERROR
+OUTPUT
-Note: checking out 'f22b25e'.
-
-You are in 'detached HEAD' state. You can look around, make experimental
-changes and commit them, and you can discard any commits you make in this
-state without impacting any branches by performing another checkout.
-
-If you want to create a new branch to retain commits you create, you may
-do so (now or later) by using -b with the checkout command again. Example:
-
- git checkout -b <new-branch-name>
-
-HEAD is now at f22b25e Create a template for recipe
-
-The “detached HEAD” is like “look, but don’t touch” here, so you
-shouldn’t make any changes in this state. After investigating your
-repo’s past state, reattach your HEAD
with
-git checkout main
.
-
-
+# Guacamole
+## Ingredients
+* avocado
+* lime
+* salt
+## Instructions
It’s important to remember that we must use the commit number that
identifies the state of the repository before the change we’re
trying to undo. A common mistake is to use the number of the commit in
which we made the change we’re trying to discard. In the example below,
we want to retrieve the state from before the most recent commit
-(HEAD~1
), which is commit f22b25e
:
-So, to put it all together, here’s how Git works in cartoon form:
+(HEAD~1
), which is commit f22b25e
. We use the
+.
to mean all files:
+So, to put it all together, here’s how Git works in cartoon form:
-
-
-
-
-Simplifying the Common Case
-
-If you read the output of git status
carefully, you’ll
-see that it includes this hint:
-
-As it says, git checkout
without a version identifier
-restores files to the state saved in HEAD
. The double dash
---
is needed to separate the names of the files being
-recovered from the command itself: without it, Git would try to use the
-name of the file as the commit identifier.
-
-
-
-The fact that files can be reverted one by one tends to change the
+
The fact that files can be reverted one by one tends to change the
way people organize their work. If everything is in one large document,
it’s hard (but not impossible) to undo changes to the introduction
without also undoing changes made later to the conclusion. If the
@@ -2508,10 +2440,10 @@
Recovering Older Versions of a File
Git! Which commands below will let her recover the last committed
version of her Python script called data_cruncher.py
?
-$ git checkout HEAD
-$ git checkout HEAD data_cruncher.py
-$ git checkout HEAD~1 data_cruncher.py
-$ git checkout <unique ID of last commit> data_cruncher.py
+$ git restore
+$ git restore data_cruncher.py
+$ git restore -s HEAD~1 data_cruncher.py
+$ git restore -s <unique ID of last commit> data_cruncher.py
Both 2 and 4
@@ -2525,7 +2457,7 @@ Show me the solution
The answer is (5)-Both 2 and 4.
-The checkout
command restores files from the repository,
+
The restore
command restores files from the repository,
overwriting the files in your working directory. Answers 2 and 4 both
restore the latest version in the repository of the
file data_cruncher.py
. Answer 2 uses HEAD
to
@@ -2534,15 +2466,9 @@
Show me the solution
Answer 3 gets the version of data_cruncher.py
from the
commit before HEAD
, which is NOT what we
wanted.
-Answer 1 can be dangerous! Without a filename,
-git checkout
will restore all files in the
-current directory (and all directories below it) to their state at the
-commit specified. This command will restore
-data_cruncher.py
to the latest commit version, but it will
-also restore any other files that are changed to that version,
-erasing any changes you may have made to those files! As discussed
-above, you are left in a detached HEAD
state, and
-you don’t want to be there.
+Answer 1 results in an error. You need to specify a file to restore.
+If you want to restore all files you should use
+git restore .
@@ -2561,10 +2487,10 @@ Reverting a Commit
git revert [erroneous commit ID]
will create a new commit
that reverses the erroneous commit.
The command git revert
is different from
-git checkout [commit ID]
because git checkout
-returns the files not yet committed within the local repository to a
-previous state, whereas git revert
reverses changes
-committed to the local and project repositories.
+git restore -s [commit ID] .
because
+git restore
returns the files not yet committed within the
+local repository to a previous state, whereas git revert
+reverses changes committed to the local and project repositories.
Below are the right steps and explanations for Jennifer to use
git revert
, what is the missing command?
@@ -2573,7 +2499,7 @@ Reverting a Commit
e.g. 0b1d055).
git revert [commit ID]
Type in the new commit message.
-Save and close
+Save and close.
@@ -2603,33 +2529,33 @@ Show me the solution
Understanding Workflow and History
What is the output of the last command in
-
+
BASH
-$ cd recipes
-$ echo "I like tomatos, therefore I like ketchup" > ketchup.md
-$ git add ketchup.md
-$ echo "ketchup enchances pasta dishes" > ketchup.md
-$ git commit -m "my opinions about the red sauce"
-$ git checkout HEAD ketchup.md
-$ cat ketchup.md # this will print the content of ketchup.md on screen
+$ cd recipes
+$ echo "I like tomatoes, therefore I like ketchup" > ketchup.md
+$ git add ketchup.md
+$ echo "ketchup enhances pasta dishes" >> ketchup.md
+$ git commit -m "My opinions about the red sauce"
+$ git restore ketchup.md
+$ cat ketchup.md # this will print the content of ketchup.md on screen
-
OUTPUT
- ketchup enchances pasta dishes
+ ketchup enhances pasta dishes
-
OUTPUT
- I like tomatos, therefore I like ketchup
+ I like tomatoes, therefore I like ketchup
-
OUTPUT
- I like tomatos, therefore I like ketchup
- ketchup enchances pasta dishes
+ I like tomatoes, therefore I like ketchup
+ ketchup enhances pasta dishes
-
OUTPUT
@@ -2653,18 +2579,18 @@ Show me the solution
git add ketchup.md
places the current version of
ketchup.md
into the staging area. not the version in the
staging area.
-
So, when git commit -m "my opinions about the red sauce"
+
So, when git commit -m "My opinions about the red sauce"
is executed, the version of ketchup.md
committed to the
repository is the one from the staging area and has only one line.
At this time, the working copy still has the second line (and
git status
will show that the file is modified).
-However, git checkout HEAD ketchup.md
replaces the working
-copy with the most recently committed version of
-ketchup.md
. So, cat ketchup.md
will output
+However, git restore ketchup.md
replaces the working copy
+with the most recently committed version of ketchup.md
. So,
+cat ketchup.md
will output
OUTPUT
-I like tomatos, therefore I like ketchup
+I like tomatoes, therefore I like ketchup
@@ -2695,11 +2621,11 @@ Checking Understanding of
Getting Rid of Staged Changes
-git checkout
can be used to restore a previous commit
+
git restore
can be used to restore a previous commit
when unstaged changes have been made, but will it also work for changes
that have been staged but not committed? Make a change to
guacamole.md
, add that change using git add
,
-then use git checkout
to see if you can remove your
+then use git restore
to see if you can remove your
change.
@@ -2711,41 +2637,34 @@ Show me the solution
-After adding a change, git checkout
can not be used
+
After adding a change, git restore
can not be used
directly. Let’s look at the output of git status
:
OUTPUT
On branch main
Changes to be committed:
- (use "git reset HEAD <file>..." to unstage)
-
+ (use "git restore --staged <file>..." to unstage)
modified: guacamole.md
Note that if you don’t have the same output you may either have
forgotten to change the file, or you have added it and
committed it.
-Using the command git checkout -- guacamole.md
now does
-not give an error, but it does not restore the file either. Git
-helpfully tells us that we need to use git reset
first to
+
Using the command git restore guacamole.md
now does not
+give an error, but it does not restore the file either. Git helpfully
+tells us that we need to use git restore --staged
first to
unstage the file:
-
+
-
-OUTPUT
+
Now, git status
gives us:
+
+BASH
-Unstaged changes after reset:
-M guacamole.md
-
-
-Now, `git status` gives us:
-
-```bash
-$ git status
+$ git status
OUTPUT
@@ -2753,19 +2672,18 @@ OUTPUT<
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
- (use "git checkout -- <file>..." to discard changes in working directory)
-
+ (use "git git restore <file>..." to discard changes in working directory)
modified: guacamole.md
no changes added to commit (use "git add" and/or "git commit -a")
-This means we can now use git checkout
to restore the
+
This means we can now use git restore
to restore the
file to the previous commit:
-
+
OUTPUT
@@ -2794,28 +2712,28 @@ Explore and Summarize Histories
Recall that the git diff
command allows us to explore
one specific file, e.g., git diff guacamole.md
. We can
apply a similar idea here.
-
+
Unfortunately some of these commit messages are very ambiguous, e.g.,
update files
. How can you search through these files?
Both git diff
and git log
are very useful
and they summarize a different part of the history for you. Is it
possible to combine both? Let’s try the following:
-
+
You should get a long list of output, and you should be able to see
both commit messages and the difference between each commit.
Question: What does the following command do?
-
@@ -2831,7 +2749,7 @@ Key Points
-
git diff
displays differences between commits.
-
-
git checkout
recovers old versions of files.
+git restore
recovers old versions of files.
@@ -3380,7 +3298,7 @@ BASHremote for the local
repository. The home page of the repository on GitHub includes the URL
string we need to identify it:
-
Click on the ‘SSH’ link to change the protocol from HTTPS to SSH.
+Click on the ‘SSH’ link to change the protocol from HTTPS to SSH.
@@ -3391,13 +3309,11 @@ HTTPS vs. SSH
We use SSH here because, while it requires some additional
configuration, it is a security protocol widely used by many
applications. The steps below describe SSH at a minimum level for
-GitHub. A supplemental episode to this lesson discusses advanced setup
-and concepts of SSH and key pairs, and other material supplemental to
-git related SSH.
+GitHub.
-Copy that URL from the browser, go into the local
+
Copy that URL from the browser, go into the local
recipes
repository, and run this command:
BASH
@@ -3503,9 +3419,10 @@ OUTPUT<
3.1 Create an SSH key pair
-To create an SSH key pair Vlad uses this command, where the
+
To create an SSH key pair Alfredo uses this command, where the
-t
option specifies which type of algorithm to use and
--C
attaches a comment to the key (here, Vlad’s email):
+-C
attaches a comment to the key (here, Alfredo’s
+email):
BASH
@@ -3530,7 +3447,10 @@ OUTPUT<
Now, it is prompting Alfredo for a passphrase. Since he is using his
kitchen’s laptop that other people sometimes have access to, he wants to
create a passphrase. Be sure to use something memorable or save your
-passphrase somewhere, as there is no “reset my password” option.
+passphrase somewhere, as there is no “reset my password” option. Note
+that, when typing a passphrase on a terminal, there won’t be any visual
+feedback of your typing. This is normal: your passphrase will be
+recorded even if you see nothing changing on your screen.
OUTPUT
@@ -3613,13 +3533,12 @@ OUTPUT<
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDmRA3d51X0uu9wXek559gfn6UFNF69yZjChyBIU2qKI a.linguini@ratatouille.fr
Now, going to GitHub.com, click on your profile icon in the top right
-corner to get the drop-down menu. Click “Settings,” then on the settings
-page, click “SSH and GPG keys,” on the left side “Account settings”
-menu. Click the “New SSH key” button on the right side. Now, you can add
-the title (Alfredo uses the title “Alfredo’s Kitchen Laptop” so he can
-remember where the original key pair files are located), paste your SSH
-key into the field, and click the “Add SSH key” to complete the
-setup.
+corner to get the drop-down menu. Click “Settings”, then on the settings
+page, click “SSH and GPG keys”, on the left side “Access” menu. Click
+the “New SSH key” button on the right side. Now, you can add the title
+(Alfredo uses the title “Alfredo’s Kitchen Laptop” so he can remember
+where the original key pair files are located), paste your SSH key into
+the field, and click the “Add SSH key” to complete the setup.
Now that we’ve set that up, let’s check our authentication again from
the command line.
@@ -4221,7 +4140,7 @@ Review Changes
-
+
On the command line, the Collaborator can use
git fetch origin main
to get the remote changes into the
@@ -4467,9 +4386,9 @@
OUTPUT<
-You may need to tell git what to do
+You may need to tell Git what to do
-If you see the below in your output, git is asking what it should
+
If you see the below in your output, Git is asking what it should
do.
OUTPUT
@@ -4487,7 +4406,7 @@ OUTPUT<
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
-In newer versions of git it gives you the option of specifying
+
In newer versions of Git it gives you the option of specifying
different behaviours when a pull would merge divergent branches. In our
case we want ‘the default strategy’. To use this strategy run the
following command to select it as the default thing git should do.
@@ -4714,7 +4633,7 @@ Conflicts on Non-textual files
-
+
Let’s try it. Suppose Alfredo takes a picture of its guacamole and
calls it guacamole.jpg
.
@@ -4957,7 +4876,7 @@ A Typical Work Session
-
+
BASH
-$ cd ~/Desktop # return to Desktop directory
-$ cd recipes # go into recipes directory, which is already a Git repository
-$ ls -a # ensure the .git subdirectory is still present in the recipes directory
-$ mkdir desserts # make a sub-directory recipes/desserts
-$ cd desserts # go into desserts subdirectory
-$ git init # make the desserts subdirectory a Git repository
-$ ls -a # ensure the .git subdirectory is present indicating we have created a new Git repository
+$ cd ~/Desktop # return to Desktop directory
+$ cd recipes # go into recipes directory, which is already a Git repository
+$ ls -a # ensure the .git subdirectory is still present in the recipes directory
+$ mkdir desserts # make a sub-directory recipes/desserts
+$ cd desserts # go into desserts subdirectory
+$ git init # make the desserts subdirectory a Git repository
+$ ls -a # ensure the .git subdirectory is present indicating we have created a new Git repository
Is the git init
command, run inside the
desserts
subdirectory, required for tracking files stored
@@ -1092,7 +1078,7 @@
BASH
Show me the solution
-
+
No. Alfredo does not need to make the desserts
subdirectory a Git repository because the recipes
@@ -1108,10 +1094,10 @@
Show me the solution
in the directory, check the output of git status
. If it
looks like the following, you are good to go to create a new repository
as shown above:
-
+
OUTPUT
@@ -1141,7 +1127,7 @@ Correcting git init
Mistakes
-
+
Background
@@ -1150,10 +1136,10 @@ Background
+
Similarly a directory can be removed using
rm -r dirname
. If the files or folder being removed in this
@@ -1167,10 +1153,10 @@
Solution
+
But be careful! Running this command in the wrong directory will
remove the entire Git history of a project you might want to keep. In
@@ -1277,7 +1263,7 @@
OUTPUT<
guacamole.md
-guacamole.md
contains a single line, which we can see by
+
guacamole.md
contains three lines, which we can see by
running:
BASH
@@ -1458,7 +1444,7 @@ OUTPUT<
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
- (use "git checkout -- <file>..." to discard changes in working directory)
+ (use "git restore <file>..." to discard changes in working directory)
modified: guacamole.md
@@ -1523,7 +1509,7 @@ OUTPUT<
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
- (use "git checkout -- <file>..." to discard changes in working directory)
+ (use "git restore <file>..." to discard changes in working directory)
modified: guacamole.md
@@ -1880,7 +1866,7 @@ Choosing a Commit Message
-
+
Answer 1 is not descriptive enough, and the purpose of the commit is
unclear; and answer 2 is redundant to using “git diff” to see what
@@ -1931,7 +1917,7 @@
BASH
Show me the solution
-
+
- Would only create a commit if files have already been staged.
@@ -1970,7 +1956,7 @@ Committing Multiple Files
-
+
First we make our changes to the guacamole.md
and
groceries.md
files:
@@ -2061,7 +2047,7 @@
-
+
If needed, move out of the recipes
folder:
@@ -2274,10 +2260,10 @@ OUTPUT<
HEAD~1
means “the previous commit”, while
HEAD~123
goes back 123 commits from where we are now.
We can also refer to commits using those long strings of digits and
-letters that git log
displays. These are unique IDs for the
-changes, and “unique” really does mean unique: every change to any set
-of files on any computer has a unique 40-character identifier. Our first
-commit was given the ID
+letters that both git log
and git show
+display. These are unique IDs for the changes, and “unique” really does
+mean unique: every change to any set of files on any computer has a
+unique 40-character identifier. Our first commit was given the ID
f22b25e3233b4645dabd0d81e651fe074bd8e73b
, so let’s try
this:
@@ -2317,7 +2303,7 @@ OUTPUT<
--- a/guacamole.md
+++ b/guacamole.md
@@ -1,3 +1,7 @@
- # Gucamole
+ # Guacamole
## Ingredients
+* avocado
+* lime
@@ -2342,18 +2328,17 @@ OUTPUT<
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
- (use "git checkout -- <file>..." to discard changes in working directory)
-
+ (use "git restore <file>..." to discard changes in working directory)
modified: guacamole.md
no changes added to commit (use "git add" and/or "git commit -a")
We can put things back the way they were by using
-git checkout
:
+git restore
:
@@ -2366,15 +2351,15 @@ OUTPUT<
* salt
## Instructions
-As you might guess from its name, git checkout
checks
-out (i.e., restores) an old version of a file. In this case, we’re
-telling Git that we want to recover the version of the file recorded in
-HEAD
, which is the last saved commit. If we want to go back
-even further, we can use a commit identifier instead:
+As you might guess from its name, git restore
restores
+an old version of a file. By default, it recovers the version of the
+file recorded in HEAD
, which is the last saved commit. If
+we want to go back even further, we can use a commit identifier instead,
+using -s
option:
BASH
@@ -2397,97 +2382,44 @@ BASHOUTPUT
On branch main
-Changes to be committed:
- (use "git reset HEAD <file>..." to unstage)
-
+Changes not staged for commit:
+ (use "git add <file>..." to update what will be committed)
+ (use "git restore <file>..." to discard changes in working directory)
modified: guacamole.md
+
+no changes added to commit (use "git add" and/or "git commit -a")
-Notice that the changes are currently in the staging area. Again, we
-can put things back the way they were by using
-git checkout
:
+Notice that the changes are not currently in the staging area, and
+have not been committed. If we wished, we can put things back the way
+they were at the last commit by using git restore
to
+overwrite the working copy with the last committed version:
-
-
-
-
-
-Don’t Lose Your HEAD
-
-Above we used
-
-to revert guacamole.md
to its state after the commit
-f22b25e
. But be careful! The command checkout
-has other important functionalities and Git will misunderstand your
-intentions if you are not accurate with the typing. For example, if you
-forget guacamole.md
in the previous command.
-
-ERROR
+OUTPUT
-Note: checking out 'f22b25e'.
-
-You are in 'detached HEAD' state. You can look around, make experimental
-changes and commit them, and you can discard any commits you make in this
-state without impacting any branches by performing another checkout.
-
-If you want to create a new branch to retain commits you create, you may
-do so (now or later) by using -b with the checkout command again. Example:
-
- git checkout -b <new-branch-name>
-
-HEAD is now at f22b25e Create a template for recipe
-
-The “detached HEAD” is like “look, but don’t touch” here, so you
-shouldn’t make any changes in this state. After investigating your
-repo’s past state, reattach your HEAD
with
-git checkout main
.
-
-
+# Guacamole
+## Ingredients
+* avocado
+* lime
+* salt
+## Instructions
It’s important to remember that we must use the commit number that
identifies the state of the repository before the change we’re
trying to undo. A common mistake is to use the number of the commit in
which we made the change we’re trying to discard. In the example below,
we want to retrieve the state from before the most recent commit
-(HEAD~1
), which is commit f22b25e
:
-So, to put it all together, here’s how Git works in cartoon form:
+(HEAD~1
), which is commit f22b25e
. We use the
+.
to mean all files:
+So, to put it all together, here’s how Git works in cartoon form:
-
-
-
-
-Simplifying the Common Case
-
-If you read the output of git status
carefully, you’ll
-see that it includes this hint:
-
-As it says, git checkout
without a version identifier
-restores files to the state saved in HEAD
. The double dash
---
is needed to separate the names of the files being
-recovered from the command itself: without it, Git would try to use the
-name of the file as the commit identifier.
-
-
-
-The fact that files can be reverted one by one tends to change the
+
The fact that files can be reverted one by one tends to change the
way people organize their work. If everything is in one large document,
it’s hard (but not impossible) to undo changes to the introduction
without also undoing changes made later to the conclusion. If the
@@ -2508,10 +2440,10 @@
Recovering Older Versions of a File
Git! Which commands below will let her recover the last committed
version of her Python script called data_cruncher.py
?
-$ git checkout HEAD
-$ git checkout HEAD data_cruncher.py
-$ git checkout HEAD~1 data_cruncher.py
-$ git checkout <unique ID of last commit> data_cruncher.py
+$ git restore
+$ git restore data_cruncher.py
+$ git restore -s HEAD~1 data_cruncher.py
+$ git restore -s <unique ID of last commit> data_cruncher.py
Both 2 and 4
@@ -2525,7 +2457,7 @@ Show me the solution
The answer is (5)-Both 2 and 4.
-The checkout
command restores files from the repository,
+
The restore
command restores files from the repository,
overwriting the files in your working directory. Answers 2 and 4 both
restore the latest version in the repository of the
file data_cruncher.py
. Answer 2 uses HEAD
to
@@ -2534,15 +2466,9 @@
Show me the solution
Answer 3 gets the version of data_cruncher.py
from the
commit before HEAD
, which is NOT what we
wanted.
-Answer 1 can be dangerous! Without a filename,
-git checkout
will restore all files in the
-current directory (and all directories below it) to their state at the
-commit specified. This command will restore
-data_cruncher.py
to the latest commit version, but it will
-also restore any other files that are changed to that version,
-erasing any changes you may have made to those files! As discussed
-above, you are left in a detached HEAD
state, and
-you don’t want to be there.
+Answer 1 results in an error. You need to specify a file to restore.
+If you want to restore all files you should use
+git restore .
@@ -2561,10 +2487,10 @@ Reverting a Commit
git revert [erroneous commit ID]
will create a new commit
that reverses the erroneous commit.
The command git revert
is different from
-git checkout [commit ID]
because git checkout
-returns the files not yet committed within the local repository to a
-previous state, whereas git revert
reverses changes
-committed to the local and project repositories.
+git restore -s [commit ID] .
because
+git restore
returns the files not yet committed within the
+local repository to a previous state, whereas git revert
+reverses changes committed to the local and project repositories.
Below are the right steps and explanations for Jennifer to use
git revert
, what is the missing command?
@@ -2573,7 +2499,7 @@ Reverting a Commit
e.g. 0b1d055).
git revert [commit ID]
Type in the new commit message.
-Save and close
+Save and close.
@@ -2603,33 +2529,33 @@ Show me the solution
Understanding Workflow and History
What is the output of the last command in
-
+
BASH
-$ cd recipes
-$ echo "I like tomatos, therefore I like ketchup" > ketchup.md
-$ git add ketchup.md
-$ echo "ketchup enchances pasta dishes" > ketchup.md
-$ git commit -m "my opinions about the red sauce"
-$ git checkout HEAD ketchup.md
-$ cat ketchup.md # this will print the content of ketchup.md on screen
+$ cd recipes
+$ echo "I like tomatoes, therefore I like ketchup" > ketchup.md
+$ git add ketchup.md
+$ echo "ketchup enhances pasta dishes" >> ketchup.md
+$ git commit -m "My opinions about the red sauce"
+$ git restore ketchup.md
+$ cat ketchup.md # this will print the content of ketchup.md on screen
-
OUTPUT
- ketchup enchances pasta dishes
+ ketchup enhances pasta dishes
-
OUTPUT
- I like tomatos, therefore I like ketchup
+ I like tomatoes, therefore I like ketchup
-
OUTPUT
- I like tomatos, therefore I like ketchup
- ketchup enchances pasta dishes
+ I like tomatoes, therefore I like ketchup
+ ketchup enhances pasta dishes
-
OUTPUT
@@ -2653,18 +2579,18 @@ Show me the solution
git add ketchup.md
places the current version of
ketchup.md
into the staging area. not the version in the
staging area.
-
So, when git commit -m "my opinions about the red sauce"
+
So, when git commit -m "My opinions about the red sauce"
is executed, the version of ketchup.md
committed to the
repository is the one from the staging area and has only one line.
At this time, the working copy still has the second line (and
git status
will show that the file is modified).
-However, git checkout HEAD ketchup.md
replaces the working
-copy with the most recently committed version of
-ketchup.md
. So, cat ketchup.md
will output
+However, git restore ketchup.md
replaces the working copy
+with the most recently committed version of ketchup.md
. So,
+cat ketchup.md
will output
OUTPUT
-I like tomatos, therefore I like ketchup
+I like tomatoes, therefore I like ketchup
@@ -2695,11 +2621,11 @@ Checking Understanding of
Getting Rid of Staged Changes
-git checkout
can be used to restore a previous commit
+
git restore
can be used to restore a previous commit
when unstaged changes have been made, but will it also work for changes
that have been staged but not committed? Make a change to
guacamole.md
, add that change using git add
,
-then use git checkout
to see if you can remove your
+then use git restore
to see if you can remove your
change.
@@ -2711,41 +2637,34 @@ Show me the solution
-After adding a change, git checkout
can not be used
+
After adding a change, git restore
can not be used
directly. Let’s look at the output of git status
:
OUTPUT
On branch main
Changes to be committed:
- (use "git reset HEAD <file>..." to unstage)
-
+ (use "git restore --staged <file>..." to unstage)
modified: guacamole.md
Note that if you don’t have the same output you may either have
forgotten to change the file, or you have added it and
committed it.
-Using the command git checkout -- guacamole.md
now does
-not give an error, but it does not restore the file either. Git
-helpfully tells us that we need to use git reset
first to
+
Using the command git restore guacamole.md
now does not
+give an error, but it does not restore the file either. Git helpfully
+tells us that we need to use git restore --staged
first to
unstage the file:
-
+
-
-OUTPUT
+
Now, git status
gives us:
+
+BASH
-Unstaged changes after reset:
-M guacamole.md
-
-
-Now, `git status` gives us:
-
-```bash
-$ git status
+$ git status
OUTPUT
@@ -2753,19 +2672,18 @@ OUTPUT<
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
- (use "git checkout -- <file>..." to discard changes in working directory)
-
+ (use "git git restore <file>..." to discard changes in working directory)
modified: guacamole.md
no changes added to commit (use "git add" and/or "git commit -a")
-This means we can now use git checkout
to restore the
+
This means we can now use git restore
to restore the
file to the previous commit:
-
+
OUTPUT
@@ -2794,28 +2712,28 @@ Explore and Summarize Histories
Recall that the git diff
command allows us to explore
one specific file, e.g., git diff guacamole.md
. We can
apply a similar idea here.
-
+
Unfortunately some of these commit messages are very ambiguous, e.g.,
update files
. How can you search through these files?
Both git diff
and git log
are very useful
and they summarize a different part of the history for you. Is it
possible to combine both? Let’s try the following:
-
+
You should get a long list of output, and you should be able to see
both commit messages and the difference between each commit.
Question: What does the following command do?
-
@@ -2831,7 +2749,7 @@ Key Points
-
git diff
displays differences between commits.
-
-
git checkout
recovers old versions of files.
+git restore
recovers old versions of files.
@@ -3380,7 +3298,7 @@ BASHremote for the local
repository. The home page of the repository on GitHub includes the URL
string we need to identify it:
-
Click on the ‘SSH’ link to change the protocol from HTTPS to SSH.
+Click on the ‘SSH’ link to change the protocol from HTTPS to SSH.
@@ -3391,13 +3309,11 @@ HTTPS vs. SSH
We use SSH here because, while it requires some additional
configuration, it is a security protocol widely used by many
applications. The steps below describe SSH at a minimum level for
-GitHub. A supplemental episode to this lesson discusses advanced setup
-and concepts of SSH and key pairs, and other material supplemental to
-git related SSH.
+GitHub.
-Copy that URL from the browser, go into the local
+
Copy that URL from the browser, go into the local
recipes
repository, and run this command:
BASH
@@ -3503,9 +3419,10 @@ OUTPUT<
3.1 Create an SSH key pair
-To create an SSH key pair Vlad uses this command, where the
+
To create an SSH key pair Alfredo uses this command, where the
-t
option specifies which type of algorithm to use and
--C
attaches a comment to the key (here, Vlad’s email):
+-C
attaches a comment to the key (here, Alfredo’s
+email):
BASH
@@ -3530,7 +3447,10 @@ OUTPUT<
Now, it is prompting Alfredo for a passphrase. Since he is using his
kitchen’s laptop that other people sometimes have access to, he wants to
create a passphrase. Be sure to use something memorable or save your
-passphrase somewhere, as there is no “reset my password” option.
+passphrase somewhere, as there is no “reset my password” option. Note
+that, when typing a passphrase on a terminal, there won’t be any visual
+feedback of your typing. This is normal: your passphrase will be
+recorded even if you see nothing changing on your screen.
OUTPUT
@@ -3613,13 +3533,12 @@ OUTPUT<
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDmRA3d51X0uu9wXek559gfn6UFNF69yZjChyBIU2qKI a.linguini@ratatouille.fr
Now, going to GitHub.com, click on your profile icon in the top right
-corner to get the drop-down menu. Click “Settings,” then on the settings
-page, click “SSH and GPG keys,” on the left side “Account settings”
-menu. Click the “New SSH key” button on the right side. Now, you can add
-the title (Alfredo uses the title “Alfredo’s Kitchen Laptop” so he can
-remember where the original key pair files are located), paste your SSH
-key into the field, and click the “Add SSH key” to complete the
-setup.
+corner to get the drop-down menu. Click “Settings”, then on the settings
+page, click “SSH and GPG keys”, on the left side “Access” menu. Click
+the “New SSH key” button on the right side. Now, you can add the title
+(Alfredo uses the title “Alfredo’s Kitchen Laptop” so he can remember
+where the original key pair files are located), paste your SSH key into
+the field, and click the “Add SSH key” to complete the setup.
Now that we’ve set that up, let’s check our authentication again from
the command line.
@@ -4221,7 +4140,7 @@ Review Changes
-
+
On the command line, the Collaborator can use
git fetch origin main
to get the remote changes into the
@@ -4467,9 +4386,9 @@
OUTPUT<
-You may need to tell git what to do
+You may need to tell Git what to do
-If you see the below in your output, git is asking what it should
+
If you see the below in your output, Git is asking what it should
do.
OUTPUT
@@ -4487,7 +4406,7 @@ OUTPUT<
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
-In newer versions of git it gives you the option of specifying
+
In newer versions of Git it gives you the option of specifying
different behaviours when a pull would merge divergent branches. In our
case we want ‘the default strategy’. To use this strategy run the
following command to select it as the default thing git should do.
@@ -4714,7 +4633,7 @@ Conflicts on Non-textual files
-
+
Let’s try it. Suppose Alfredo takes a picture of its guacamole and
calls it guacamole.jpg
.
@@ -4957,7 +4876,7 @@ A Typical Work Session
-
+
No. Alfredo does not need to make the desserts
subdirectory a Git repository because the recipes
@@ -1108,10 +1094,10 @@
Show me the solution
in the directory, check the output ofgit status
. If it
looks like the following, you are good to go to create a new repository
as shown above:
-OUTPUT
@@ -1141,7 +1127,7 @@ Correcting git init
Mistakes
-
+
Background
@@ -1150,10 +1136,10 @@ Background
+
Similarly a directory can be removed using
rm -r dirname
. If the files or folder being removed in this
@@ -1167,10 +1153,10 @@
Solution
+
But be careful! Running this command in the wrong directory will
remove the entire Git history of a project you might want to keep. In
@@ -1277,7 +1263,7 @@
OUTPUT<
guacamole.md
-guacamole.md
contains a single line, which we can see by
+
guacamole.md
contains three lines, which we can see by
running:
BASH
@@ -1458,7 +1444,7 @@ OUTPUT<
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
- (use "git checkout -- <file>..." to discard changes in working directory)
+ (use "git restore <file>..." to discard changes in working directory)
modified: guacamole.md
@@ -1523,7 +1509,7 @@ OUTPUT<
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
- (use "git checkout -- <file>..." to discard changes in working directory)
+ (use "git restore <file>..." to discard changes in working directory)
modified: guacamole.md
@@ -1880,7 +1866,7 @@ Choosing a Commit Message
-
+
Answer 1 is not descriptive enough, and the purpose of the commit is
unclear; and answer 2 is redundant to using “git diff” to see what
@@ -1931,7 +1917,7 @@
BASH
Show me the solution
-
+
- Would only create a commit if files have already been staged.
@@ -1970,7 +1956,7 @@ Committing Multiple Files
-
+
First we make our changes to the guacamole.md
and
groceries.md
files:
@@ -2061,7 +2047,7 @@
-
+
If needed, move out of the recipes
folder:
@@ -2274,10 +2260,10 @@ OUTPUT<
HEAD~1
means “the previous commit”, while
HEAD~123
goes back 123 commits from where we are now.
We can also refer to commits using those long strings of digits and
-letters that git log
displays. These are unique IDs for the
-changes, and “unique” really does mean unique: every change to any set
-of files on any computer has a unique 40-character identifier. Our first
-commit was given the ID
+letters that both git log
and git show
+display. These are unique IDs for the changes, and “unique” really does
+mean unique: every change to any set of files on any computer has a
+unique 40-character identifier. Our first commit was given the ID
f22b25e3233b4645dabd0d81e651fe074bd8e73b
, so let’s try
this:
@@ -2317,7 +2303,7 @@ OUTPUT<
--- a/guacamole.md
+++ b/guacamole.md
@@ -1,3 +1,7 @@
- # Gucamole
+ # Guacamole
## Ingredients
+* avocado
+* lime
@@ -2342,18 +2328,17 @@ OUTPUT<
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
- (use "git checkout -- <file>..." to discard changes in working directory)
-
+ (use "git restore <file>..." to discard changes in working directory)
modified: guacamole.md
no changes added to commit (use "git add" and/or "git commit -a")
We can put things back the way they were by using
-git checkout
:
+git restore
:
@@ -2366,15 +2351,15 @@ OUTPUT<
* salt
## Instructions
-As you might guess from its name, git checkout
checks
-out (i.e., restores) an old version of a file. In this case, we’re
-telling Git that we want to recover the version of the file recorded in
-HEAD
, which is the last saved commit. If we want to go back
-even further, we can use a commit identifier instead:
+As you might guess from its name, git restore
restores
+an old version of a file. By default, it recovers the version of the
+file recorded in HEAD
, which is the last saved commit. If
+we want to go back even further, we can use a commit identifier instead,
+using -s
option:
BASH
@@ -2397,97 +2382,44 @@ BASHOUTPUT
On branch main
-Changes to be committed:
- (use "git reset HEAD <file>..." to unstage)
-
+Changes not staged for commit:
+ (use "git add <file>..." to update what will be committed)
+ (use "git restore <file>..." to discard changes in working directory)
modified: guacamole.md
+
+no changes added to commit (use "git add" and/or "git commit -a")
-Notice that the changes are currently in the staging area. Again, we
-can put things back the way they were by using
-git checkout
:
+Notice that the changes are not currently in the staging area, and
+have not been committed. If we wished, we can put things back the way
+they were at the last commit by using git restore
to
+overwrite the working copy with the last committed version:
-
-
-
-
-
-Don’t Lose Your HEAD
-
-Above we used
-
-to revert guacamole.md
to its state after the commit
-f22b25e
. But be careful! The command checkout
-has other important functionalities and Git will misunderstand your
-intentions if you are not accurate with the typing. For example, if you
-forget guacamole.md
in the previous command.
-
-ERROR
+OUTPUT
-Note: checking out 'f22b25e'.
-
-You are in 'detached HEAD' state. You can look around, make experimental
-changes and commit them, and you can discard any commits you make in this
-state without impacting any branches by performing another checkout.
-
-If you want to create a new branch to retain commits you create, you may
-do so (now or later) by using -b with the checkout command again. Example:
-
- git checkout -b <new-branch-name>
-
-HEAD is now at f22b25e Create a template for recipe
-
-The “detached HEAD” is like “look, but don’t touch” here, so you
-shouldn’t make any changes in this state. After investigating your
-repo’s past state, reattach your HEAD
with
-git checkout main
.
-
-
+# Guacamole
+## Ingredients
+* avocado
+* lime
+* salt
+## Instructions
It’s important to remember that we must use the commit number that
identifies the state of the repository before the change we’re
trying to undo. A common mistake is to use the number of the commit in
which we made the change we’re trying to discard. In the example below,
we want to retrieve the state from before the most recent commit
-(HEAD~1
), which is commit f22b25e
:
-So, to put it all together, here’s how Git works in cartoon form:
+(HEAD~1
), which is commit f22b25e
. We use the
+.
to mean all files:
+So, to put it all together, here’s how Git works in cartoon form:
-
-
-
-
-Simplifying the Common Case
-
-If you read the output of git status
carefully, you’ll
-see that it includes this hint:
-
-As it says, git checkout
without a version identifier
-restores files to the state saved in HEAD
. The double dash
---
is needed to separate the names of the files being
-recovered from the command itself: without it, Git would try to use the
-name of the file as the commit identifier.
-
-
-
-The fact that files can be reverted one by one tends to change the
+
The fact that files can be reverted one by one tends to change the
way people organize their work. If everything is in one large document,
it’s hard (but not impossible) to undo changes to the introduction
without also undoing changes made later to the conclusion. If the
@@ -2508,10 +2440,10 @@
Recovering Older Versions of a File
Git! Which commands below will let her recover the last committed
version of her Python script called data_cruncher.py
?
-$ git checkout HEAD
-$ git checkout HEAD data_cruncher.py
-$ git checkout HEAD~1 data_cruncher.py
-$ git checkout <unique ID of last commit> data_cruncher.py
+$ git restore
+$ git restore data_cruncher.py
+$ git restore -s HEAD~1 data_cruncher.py
+$ git restore -s <unique ID of last commit> data_cruncher.py
Both 2 and 4
@@ -2525,7 +2457,7 @@ Show me the solution
The answer is (5)-Both 2 and 4.
-The checkout
command restores files from the repository,
+
The restore
command restores files from the repository,
overwriting the files in your working directory. Answers 2 and 4 both
restore the latest version in the repository of the
file data_cruncher.py
. Answer 2 uses HEAD
to
@@ -2534,15 +2466,9 @@
Show me the solution
Answer 3 gets the version of data_cruncher.py
from the
commit before HEAD
, which is NOT what we
wanted.
-Answer 1 can be dangerous! Without a filename,
-git checkout
will restore all files in the
-current directory (and all directories below it) to their state at the
-commit specified. This command will restore
-data_cruncher.py
to the latest commit version, but it will
-also restore any other files that are changed to that version,
-erasing any changes you may have made to those files! As discussed
-above, you are left in a detached HEAD
state, and
-you don’t want to be there.
+Answer 1 results in an error. You need to specify a file to restore.
+If you want to restore all files you should use
+git restore .
@@ -2561,10 +2487,10 @@ Reverting a Commit
git revert [erroneous commit ID]
will create a new commit
that reverses the erroneous commit.
The command git revert
is different from
-git checkout [commit ID]
because git checkout
-returns the files not yet committed within the local repository to a
-previous state, whereas git revert
reverses changes
-committed to the local and project repositories.
+git restore -s [commit ID] .
because
+git restore
returns the files not yet committed within the
+local repository to a previous state, whereas git revert
+reverses changes committed to the local and project repositories.
Below are the right steps and explanations for Jennifer to use
git revert
, what is the missing command?
@@ -2573,7 +2499,7 @@ Reverting a Commit
e.g. 0b1d055).
git revert [commit ID]
Type in the new commit message.
-Save and close
+Save and close.
@@ -2603,33 +2529,33 @@ Show me the solution
Understanding Workflow and History
What is the output of the last command in
-
+
BASH
-$ cd recipes
-$ echo "I like tomatos, therefore I like ketchup" > ketchup.md
-$ git add ketchup.md
-$ echo "ketchup enchances pasta dishes" > ketchup.md
-$ git commit -m "my opinions about the red sauce"
-$ git checkout HEAD ketchup.md
-$ cat ketchup.md # this will print the content of ketchup.md on screen
+$ cd recipes
+$ echo "I like tomatoes, therefore I like ketchup" > ketchup.md
+$ git add ketchup.md
+$ echo "ketchup enhances pasta dishes" >> ketchup.md
+$ git commit -m "My opinions about the red sauce"
+$ git restore ketchup.md
+$ cat ketchup.md # this will print the content of ketchup.md on screen
-
OUTPUT
- ketchup enchances pasta dishes
+ ketchup enhances pasta dishes
-
OUTPUT
- I like tomatos, therefore I like ketchup
+ I like tomatoes, therefore I like ketchup
-
OUTPUT
- I like tomatos, therefore I like ketchup
- ketchup enchances pasta dishes
+ I like tomatoes, therefore I like ketchup
+ ketchup enhances pasta dishes
-
OUTPUT
@@ -2653,18 +2579,18 @@ Show me the solution
git add ketchup.md
places the current version of
ketchup.md
into the staging area. not the version in the
staging area.
-
So, when git commit -m "my opinions about the red sauce"
+
So, when git commit -m "My opinions about the red sauce"
is executed, the version of ketchup.md
committed to the
repository is the one from the staging area and has only one line.
At this time, the working copy still has the second line (and
git status
will show that the file is modified).
-However, git checkout HEAD ketchup.md
replaces the working
-copy with the most recently committed version of
-ketchup.md
. So, cat ketchup.md
will output
+However, git restore ketchup.md
replaces the working copy
+with the most recently committed version of ketchup.md
. So,
+cat ketchup.md
will output
OUTPUT
-I like tomatos, therefore I like ketchup
+I like tomatoes, therefore I like ketchup
@@ -2695,11 +2621,11 @@ Checking Understanding of
Getting Rid of Staged Changes
-git checkout
can be used to restore a previous commit
+
git restore
can be used to restore a previous commit
when unstaged changes have been made, but will it also work for changes
that have been staged but not committed? Make a change to
guacamole.md
, add that change using git add
,
-then use git checkout
to see if you can remove your
+then use git restore
to see if you can remove your
change.
@@ -2711,41 +2637,34 @@ Show me the solution
-After adding a change, git checkout
can not be used
+
After adding a change, git restore
can not be used
directly. Let’s look at the output of git status
:
OUTPUT
On branch main
Changes to be committed:
- (use "git reset HEAD <file>..." to unstage)
-
+ (use "git restore --staged <file>..." to unstage)
modified: guacamole.md
Note that if you don’t have the same output you may either have
forgotten to change the file, or you have added it and
committed it.
-Using the command git checkout -- guacamole.md
now does
-not give an error, but it does not restore the file either. Git
-helpfully tells us that we need to use git reset
first to
+
Using the command git restore guacamole.md
now does not
+give an error, but it does not restore the file either. Git helpfully
+tells us that we need to use git restore --staged
first to
unstage the file:
-
+
-
-OUTPUT
+
Now, git status
gives us:
+
+BASH
-Unstaged changes after reset:
-M guacamole.md
-
-
-Now, `git status` gives us:
-
-```bash
-$ git status
+$ git status
OUTPUT
@@ -2753,19 +2672,18 @@ OUTPUT<
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
- (use "git checkout -- <file>..." to discard changes in working directory)
-
+ (use "git git restore <file>..." to discard changes in working directory)
modified: guacamole.md
no changes added to commit (use "git add" and/or "git commit -a")
-This means we can now use git checkout
to restore the
+
This means we can now use git restore
to restore the
file to the previous commit:
-
+
OUTPUT
@@ -2794,28 +2712,28 @@ Explore and Summarize Histories
Recall that the git diff
command allows us to explore
one specific file, e.g., git diff guacamole.md
. We can
apply a similar idea here.
-
+
Unfortunately some of these commit messages are very ambiguous, e.g.,
update files
. How can you search through these files?
Both git diff
and git log
are very useful
and they summarize a different part of the history for you. Is it
possible to combine both? Let’s try the following:
-
+
You should get a long list of output, and you should be able to see
both commit messages and the difference between each commit.
Question: What does the following command do?
-
@@ -2831,7 +2749,7 @@ Key Points
-
git diff
displays differences between commits.
-
-
git checkout
recovers old versions of files.
+git restore
recovers old versions of files.
@@ -3380,7 +3298,7 @@ BASHremote for the local
repository. The home page of the repository on GitHub includes the URL
string we need to identify it:
-
Click on the ‘SSH’ link to change the protocol from HTTPS to SSH.
+Click on the ‘SSH’ link to change the protocol from HTTPS to SSH.
@@ -3391,13 +3309,11 @@ HTTPS vs. SSH
We use SSH here because, while it requires some additional
configuration, it is a security protocol widely used by many
applications. The steps below describe SSH at a minimum level for
-GitHub. A supplemental episode to this lesson discusses advanced setup
-and concepts of SSH and key pairs, and other material supplemental to
-git related SSH.
+GitHub.
-Copy that URL from the browser, go into the local
+
Copy that URL from the browser, go into the local
recipes
repository, and run this command:
BASH
@@ -3503,9 +3419,10 @@ OUTPUT<
3.1 Create an SSH key pair
-To create an SSH key pair Vlad uses this command, where the
+
To create an SSH key pair Alfredo uses this command, where the
-t
option specifies which type of algorithm to use and
--C
attaches a comment to the key (here, Vlad’s email):
+-C
attaches a comment to the key (here, Alfredo’s
+email):
BASH
@@ -3530,7 +3447,10 @@ OUTPUT<
Now, it is prompting Alfredo for a passphrase. Since he is using his
kitchen’s laptop that other people sometimes have access to, he wants to
create a passphrase. Be sure to use something memorable or save your
-passphrase somewhere, as there is no “reset my password” option.
+passphrase somewhere, as there is no “reset my password” option. Note
+that, when typing a passphrase on a terminal, there won’t be any visual
+feedback of your typing. This is normal: your passphrase will be
+recorded even if you see nothing changing on your screen.
OUTPUT
@@ -3613,13 +3533,12 @@ OUTPUT<
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDmRA3d51X0uu9wXek559gfn6UFNF69yZjChyBIU2qKI a.linguini@ratatouille.fr
Now, going to GitHub.com, click on your profile icon in the top right
-corner to get the drop-down menu. Click “Settings,” then on the settings
-page, click “SSH and GPG keys,” on the left side “Account settings”
-menu. Click the “New SSH key” button on the right side. Now, you can add
-the title (Alfredo uses the title “Alfredo’s Kitchen Laptop” so he can
-remember where the original key pair files are located), paste your SSH
-key into the field, and click the “Add SSH key” to complete the
-setup.
+corner to get the drop-down menu. Click “Settings”, then on the settings
+page, click “SSH and GPG keys”, on the left side “Access” menu. Click
+the “New SSH key” button on the right side. Now, you can add the title
+(Alfredo uses the title “Alfredo’s Kitchen Laptop” so he can remember
+where the original key pair files are located), paste your SSH key into
+the field, and click the “Add SSH key” to complete the setup.
Now that we’ve set that up, let’s check our authentication again from
the command line.
@@ -4221,7 +4140,7 @@ Review Changes
-
+
On the command line, the Collaborator can use
git fetch origin main
to get the remote changes into the
@@ -4467,9 +4386,9 @@
OUTPUT<
-You may need to tell git what to do
+You may need to tell Git what to do
-If you see the below in your output, git is asking what it should
+
If you see the below in your output, Git is asking what it should
do.
OUTPUT
@@ -4487,7 +4406,7 @@ OUTPUT<
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
-In newer versions of git it gives you the option of specifying
+
In newer versions of Git it gives you the option of specifying
different behaviours when a pull would merge divergent branches. In our
case we want ‘the default strategy’. To use this strategy run the
following command to select it as the default thing git should do.
@@ -4714,7 +4633,7 @@ Conflicts on Non-textual files
-
+
Let’s try it. Suppose Alfredo takes a picture of its guacamole and
calls it guacamole.jpg
.
@@ -4957,7 +4876,7 @@ A Typical Work Session
-
+
git init
MistakesBackground
@@ -1150,10 +1136,10 @@ Background
+
Similarly a directory can be removed using
rm -r dirname
. If the files or folder being removed in this
@@ -1167,10 +1153,10 @@
Solution
+
But be careful! Running this command in the wrong directory will
remove the entire Git history of a project you might want to keep. In
@@ -1277,7 +1263,7 @@
OUTPUT<
guacamole.md
Similarly a directory can be removed using
rm -r dirname
. If the files or folder being removed in this
@@ -1167,10 +1153,10 @@
Solution
+
But be careful! Running this command in the wrong directory will
remove the entire Git history of a project you might want to keep. In
@@ -1277,7 +1263,7 @@
OUTPUT<
guacamole.md
guacamole.md
guacamole.md
contains a single line, which we can see by
+
guacamole.md
contains three lines, which we can see by
running:
BASH
@@ -1458,7 +1444,7 @@ OUTPUT<
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
- (use "git checkout -- <file>..." to discard changes in working directory)
+ (use "git restore <file>..." to discard changes in working directory)
modified: guacamole.md
@@ -1523,7 +1509,7 @@ OUTPUT<
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
- (use "git checkout -- <file>..." to discard changes in working directory)
+ (use "git restore <file>..." to discard changes in working directory)
modified: guacamole.md
@@ -1880,7 +1866,7 @@ Choosing a Commit Message
-
+
Answer 1 is not descriptive enough, and the purpose of the commit is
unclear; and answer 2 is redundant to using “git diff” to see what
@@ -1931,7 +1917,7 @@
BASH
Show me the solution
-
+
- Would only create a commit if files have already been staged.
@@ -1970,7 +1956,7 @@ Committing Multiple Files
-
+
First we make our changes to the guacamole.md
and
groceries.md
files:
@@ -2061,7 +2047,7 @@
-
+
If needed, move out of the recipes
folder:
@@ -2274,10 +2260,10 @@ OUTPUT<
HEAD~1
means “the previous commit”, while
HEAD~123
goes back 123 commits from where we are now.
We can also refer to commits using those long strings of digits and
-letters that git log
displays. These are unique IDs for the
-changes, and “unique” really does mean unique: every change to any set
-of files on any computer has a unique 40-character identifier. Our first
-commit was given the ID
+letters that both git log
and git show
+display. These are unique IDs for the changes, and “unique” really does
+mean unique: every change to any set of files on any computer has a
+unique 40-character identifier. Our first commit was given the ID
f22b25e3233b4645dabd0d81e651fe074bd8e73b
, so let’s try
this:
@@ -2317,7 +2303,7 @@ OUTPUT<
--- a/guacamole.md
+++ b/guacamole.md
@@ -1,3 +1,7 @@
- # Gucamole
+ # Guacamole
## Ingredients
+* avocado
+* lime
@@ -2342,18 +2328,17 @@ OUTPUT<
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
- (use "git checkout -- <file>..." to discard changes in working directory)
-
+ (use "git restore <file>..." to discard changes in working directory)
modified: guacamole.md
no changes added to commit (use "git add" and/or "git commit -a")
We can put things back the way they were by using
-git checkout
:
+git restore
:
@@ -2366,15 +2351,15 @@ OUTPUT<
* salt
## Instructions
-As you might guess from its name, git checkout
checks
-out (i.e., restores) an old version of a file. In this case, we’re
-telling Git that we want to recover the version of the file recorded in
-HEAD
, which is the last saved commit. If we want to go back
-even further, we can use a commit identifier instead:
+As you might guess from its name, git restore
restores
+an old version of a file. By default, it recovers the version of the
+file recorded in HEAD
, which is the last saved commit. If
+we want to go back even further, we can use a commit identifier instead,
+using -s
option:
BASH
@@ -2397,97 +2382,44 @@ BASHOUTPUT
On branch main
-Changes to be committed:
- (use "git reset HEAD <file>..." to unstage)
-
+Changes not staged for commit:
+ (use "git add <file>..." to update what will be committed)
+ (use "git restore <file>..." to discard changes in working directory)
modified: guacamole.md
+
+no changes added to commit (use "git add" and/or "git commit -a")
-Notice that the changes are currently in the staging area. Again, we
-can put things back the way they were by using
-git checkout
:
+Notice that the changes are not currently in the staging area, and
+have not been committed. If we wished, we can put things back the way
+they were at the last commit by using git restore
to
+overwrite the working copy with the last committed version:
-
-
-
-
-
-Don’t Lose Your HEAD
-
-Above we used
-
-to revert guacamole.md
to its state after the commit
-f22b25e
. But be careful! The command checkout
-has other important functionalities and Git will misunderstand your
-intentions if you are not accurate with the typing. For example, if you
-forget guacamole.md
in the previous command.
-
-ERROR
+OUTPUT
-Note: checking out 'f22b25e'.
-
-You are in 'detached HEAD' state. You can look around, make experimental
-changes and commit them, and you can discard any commits you make in this
-state without impacting any branches by performing another checkout.
-
-If you want to create a new branch to retain commits you create, you may
-do so (now or later) by using -b with the checkout command again. Example:
-
- git checkout -b <new-branch-name>
-
-HEAD is now at f22b25e Create a template for recipe
-
-The “detached HEAD” is like “look, but don’t touch” here, so you
-shouldn’t make any changes in this state. After investigating your
-repo’s past state, reattach your HEAD
with
-git checkout main
.
-
-
+# Guacamole
+## Ingredients
+* avocado
+* lime
+* salt
+## Instructions
It’s important to remember that we must use the commit number that
identifies the state of the repository before the change we’re
trying to undo. A common mistake is to use the number of the commit in
which we made the change we’re trying to discard. In the example below,
we want to retrieve the state from before the most recent commit
-(HEAD~1
), which is commit f22b25e
:
-So, to put it all together, here’s how Git works in cartoon form:
+(HEAD~1
), which is commit f22b25e
. We use the
+.
to mean all files:
+So, to put it all together, here’s how Git works in cartoon form:
-
-
-
-
-Simplifying the Common Case
-
-If you read the output of git status
carefully, you’ll
-see that it includes this hint:
-
-As it says, git checkout
without a version identifier
-restores files to the state saved in HEAD
. The double dash
---
is needed to separate the names of the files being
-recovered from the command itself: without it, Git would try to use the
-name of the file as the commit identifier.
-
-
-
-The fact that files can be reverted one by one tends to change the
+
The fact that files can be reverted one by one tends to change the
way people organize their work. If everything is in one large document,
it’s hard (but not impossible) to undo changes to the introduction
without also undoing changes made later to the conclusion. If the
@@ -2508,10 +2440,10 @@
Recovering Older Versions of a File
Git! Which commands below will let her recover the last committed
version of her Python script called data_cruncher.py
?
-$ git checkout HEAD
-$ git checkout HEAD data_cruncher.py
-$ git checkout HEAD~1 data_cruncher.py
-$ git checkout <unique ID of last commit> data_cruncher.py
+$ git restore
+$ git restore data_cruncher.py
+$ git restore -s HEAD~1 data_cruncher.py
+$ git restore -s <unique ID of last commit> data_cruncher.py
Both 2 and 4
@@ -2525,7 +2457,7 @@ Show me the solution
The answer is (5)-Both 2 and 4.
-The checkout
command restores files from the repository,
+
The restore
command restores files from the repository,
overwriting the files in your working directory. Answers 2 and 4 both
restore the latest version in the repository of the
file data_cruncher.py
. Answer 2 uses HEAD
to
@@ -2534,15 +2466,9 @@
Show me the solution
Answer 3 gets the version of data_cruncher.py
from the
commit before HEAD
, which is NOT what we
wanted.
-Answer 1 can be dangerous! Without a filename,
-git checkout
will restore all files in the
-current directory (and all directories below it) to their state at the
-commit specified. This command will restore
-data_cruncher.py
to the latest commit version, but it will
-also restore any other files that are changed to that version,
-erasing any changes you may have made to those files! As discussed
-above, you are left in a detached HEAD
state, and
-you don’t want to be there.
+Answer 1 results in an error. You need to specify a file to restore.
+If you want to restore all files you should use
+git restore .
@@ -2561,10 +2487,10 @@ Reverting a Commit
git revert [erroneous commit ID]
will create a new commit
that reverses the erroneous commit.
The command git revert
is different from
-git checkout [commit ID]
because git checkout
-returns the files not yet committed within the local repository to a
-previous state, whereas git revert
reverses changes
-committed to the local and project repositories.
+git restore -s [commit ID] .
because
+git restore
returns the files not yet committed within the
+local repository to a previous state, whereas git revert
+reverses changes committed to the local and project repositories.
Below are the right steps and explanations for Jennifer to use
git revert
, what is the missing command?
@@ -2573,7 +2499,7 @@ Reverting a Commit
e.g. 0b1d055).
git revert [commit ID]
Type in the new commit message.
-Save and close
+Save and close.
@@ -2603,33 +2529,33 @@ Show me the solution
Understanding Workflow and History
What is the output of the last command in
-
+
BASH
-$ cd recipes
-$ echo "I like tomatos, therefore I like ketchup" > ketchup.md
-$ git add ketchup.md
-$ echo "ketchup enchances pasta dishes" > ketchup.md
-$ git commit -m "my opinions about the red sauce"
-$ git checkout HEAD ketchup.md
-$ cat ketchup.md # this will print the content of ketchup.md on screen
+$ cd recipes
+$ echo "I like tomatoes, therefore I like ketchup" > ketchup.md
+$ git add ketchup.md
+$ echo "ketchup enhances pasta dishes" >> ketchup.md
+$ git commit -m "My opinions about the red sauce"
+$ git restore ketchup.md
+$ cat ketchup.md # this will print the content of ketchup.md on screen
-
OUTPUT
- ketchup enchances pasta dishes
+ ketchup enhances pasta dishes
-
OUTPUT
- I like tomatos, therefore I like ketchup
+ I like tomatoes, therefore I like ketchup
-
OUTPUT
- I like tomatos, therefore I like ketchup
- ketchup enchances pasta dishes
+ I like tomatoes, therefore I like ketchup
+ ketchup enhances pasta dishes
-
OUTPUT
@@ -2653,18 +2579,18 @@ Show me the solution
git add ketchup.md
places the current version of
ketchup.md
into the staging area. not the version in the
staging area.
-
So, when git commit -m "my opinions about the red sauce"
+
So, when git commit -m "My opinions about the red sauce"
is executed, the version of ketchup.md
committed to the
repository is the one from the staging area and has only one line.
At this time, the working copy still has the second line (and
git status
will show that the file is modified).
-However, git checkout HEAD ketchup.md
replaces the working
-copy with the most recently committed version of
-ketchup.md
. So, cat ketchup.md
will output
+However, git restore ketchup.md
replaces the working copy
+with the most recently committed version of ketchup.md
. So,
+cat ketchup.md
will output
OUTPUT
-I like tomatos, therefore I like ketchup
+I like tomatoes, therefore I like ketchup
@@ -2695,11 +2621,11 @@ Checking Understanding of
Getting Rid of Staged Changes
-git checkout
can be used to restore a previous commit
+
git restore
can be used to restore a previous commit
when unstaged changes have been made, but will it also work for changes
that have been staged but not committed? Make a change to
guacamole.md
, add that change using git add
,
-then use git checkout
to see if you can remove your
+then use git restore
to see if you can remove your
change.
@@ -2711,41 +2637,34 @@ Show me the solution
-After adding a change, git checkout
can not be used
+
After adding a change, git restore
can not be used
directly. Let’s look at the output of git status
:
OUTPUT
On branch main
Changes to be committed:
- (use "git reset HEAD <file>..." to unstage)
-
+ (use "git restore --staged <file>..." to unstage)
modified: guacamole.md
Note that if you don’t have the same output you may either have
forgotten to change the file, or you have added it and
committed it.
-Using the command git checkout -- guacamole.md
now does
-not give an error, but it does not restore the file either. Git
-helpfully tells us that we need to use git reset
first to
+
Using the command git restore guacamole.md
now does not
+give an error, but it does not restore the file either. Git helpfully
+tells us that we need to use git restore --staged
first to
unstage the file:
-
+
-
-OUTPUT
+
Now, git status
gives us:
+
+BASH
-Unstaged changes after reset:
-M guacamole.md
-
-
-Now, `git status` gives us:
-
-```bash
-$ git status
+$ git status
OUTPUT
@@ -2753,19 +2672,18 @@ OUTPUT<
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
- (use "git checkout -- <file>..." to discard changes in working directory)
-
+ (use "git git restore <file>..." to discard changes in working directory)
modified: guacamole.md
no changes added to commit (use "git add" and/or "git commit -a")
-This means we can now use git checkout
to restore the
+
This means we can now use git restore
to restore the
file to the previous commit:
-
+
OUTPUT
@@ -2794,28 +2712,28 @@ Explore and Summarize Histories
Recall that the git diff
command allows us to explore
one specific file, e.g., git diff guacamole.md
. We can
apply a similar idea here.
-
+
Unfortunately some of these commit messages are very ambiguous, e.g.,
update files
. How can you search through these files?
Both git diff
and git log
are very useful
and they summarize a different part of the history for you. Is it
possible to combine both? Let’s try the following:
-
+
You should get a long list of output, and you should be able to see
both commit messages and the difference between each commit.
Question: What does the following command do?
-
@@ -2831,7 +2749,7 @@ Key Points
-
git diff
displays differences between commits.
-
-
git checkout
recovers old versions of files.
+git restore
recovers old versions of files.
@@ -3380,7 +3298,7 @@ BASHremote for the local
repository. The home page of the repository on GitHub includes the URL
string we need to identify it:
-
Click on the ‘SSH’ link to change the protocol from HTTPS to SSH.
+Click on the ‘SSH’ link to change the protocol from HTTPS to SSH.
@@ -3391,13 +3309,11 @@ HTTPS vs. SSH
We use SSH here because, while it requires some additional
configuration, it is a security protocol widely used by many
applications. The steps below describe SSH at a minimum level for
-GitHub. A supplemental episode to this lesson discusses advanced setup
-and concepts of SSH and key pairs, and other material supplemental to
-git related SSH.
+GitHub.
-Copy that URL from the browser, go into the local
+
Copy that URL from the browser, go into the local
recipes
repository, and run this command:
BASH
@@ -3503,9 +3419,10 @@ OUTPUT<
3.1 Create an SSH key pair
-To create an SSH key pair Vlad uses this command, where the
+
To create an SSH key pair Alfredo uses this command, where the
-t
option specifies which type of algorithm to use and
--C
attaches a comment to the key (here, Vlad’s email):
+-C
attaches a comment to the key (here, Alfredo’s
+email):
BASH
@@ -3530,7 +3447,10 @@ OUTPUT<
Now, it is prompting Alfredo for a passphrase. Since he is using his
kitchen’s laptop that other people sometimes have access to, he wants to
create a passphrase. Be sure to use something memorable or save your
-passphrase somewhere, as there is no “reset my password” option.
+passphrase somewhere, as there is no “reset my password” option. Note
+that, when typing a passphrase on a terminal, there won’t be any visual
+feedback of your typing. This is normal: your passphrase will be
+recorded even if you see nothing changing on your screen.
OUTPUT
@@ -3613,13 +3533,12 @@ OUTPUT<
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDmRA3d51X0uu9wXek559gfn6UFNF69yZjChyBIU2qKI a.linguini@ratatouille.fr
Now, going to GitHub.com, click on your profile icon in the top right
-corner to get the drop-down menu. Click “Settings,” then on the settings
-page, click “SSH and GPG keys,” on the left side “Account settings”
-menu. Click the “New SSH key” button on the right side. Now, you can add
-the title (Alfredo uses the title “Alfredo’s Kitchen Laptop” so he can
-remember where the original key pair files are located), paste your SSH
-key into the field, and click the “Add SSH key” to complete the
-setup.
+corner to get the drop-down menu. Click “Settings”, then on the settings
+page, click “SSH and GPG keys”, on the left side “Access” menu. Click
+the “New SSH key” button on the right side. Now, you can add the title
+(Alfredo uses the title “Alfredo’s Kitchen Laptop” so he can remember
+where the original key pair files are located), paste your SSH key into
+the field, and click the “Add SSH key” to complete the setup.
Now that we’ve set that up, let’s check our authentication again from
the command line.
@@ -4221,7 +4140,7 @@ Review Changes
-
+
On the command line, the Collaborator can use
git fetch origin main
to get the remote changes into the
@@ -4467,9 +4386,9 @@
OUTPUT<
-You may need to tell git what to do
+You may need to tell Git what to do
-If you see the below in your output, git is asking what it should
+
If you see the below in your output, Git is asking what it should
do.
OUTPUT
@@ -4487,7 +4406,7 @@ OUTPUT<
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
-In newer versions of git it gives you the option of specifying
+
In newer versions of Git it gives you the option of specifying
different behaviours when a pull would merge divergent branches. In our
case we want ‘the default strategy’. To use this strategy run the
following command to select it as the default thing git should do.
@@ -4714,7 +4633,7 @@ Conflicts on Non-textual files
-
+
Let’s try it. Suppose Alfredo takes a picture of its guacamole and
calls it guacamole.jpg
.
@@ -4957,7 +4876,7 @@ A Typical Work Session
-
+
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
- (use "git checkout -- <file>..." to discard changes in working directory)
+ (use "git restore <file>..." to discard changes in working directory)
modified: guacamole.md
@@ -1523,7 +1509,7 @@ OUTPUT<
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
- (use "git checkout -- <file>..." to discard changes in working directory)
+ (use "git restore <file>..." to discard changes in working directory)
modified: guacamole.md
@@ -1880,7 +1866,7 @@ Choosing a Commit Message
-
+
Answer 1 is not descriptive enough, and the purpose of the commit is
unclear; and answer 2 is redundant to using “git diff” to see what
@@ -1931,7 +1917,7 @@
BASH
Show me the solution
-
+
- Would only create a commit if files have already been staged.
@@ -1970,7 +1956,7 @@ Committing Multiple Files
-
+
First we make our changes to the guacamole.md
and
groceries.md
files:
@@ -2061,7 +2047,7 @@
-
+
If needed, move out of the recipes
folder:
@@ -2274,10 +2260,10 @@ OUTPUT<
HEAD~1
means “the previous commit”, while
HEAD~123
goes back 123 commits from where we are now.
We can also refer to commits using those long strings of digits and
-letters that git log
displays. These are unique IDs for the
-changes, and “unique” really does mean unique: every change to any set
-of files on any computer has a unique 40-character identifier. Our first
-commit was given the ID
+letters that both git log
and git show
+display. These are unique IDs for the changes, and “unique” really does
+mean unique: every change to any set of files on any computer has a
+unique 40-character identifier. Our first commit was given the ID
f22b25e3233b4645dabd0d81e651fe074bd8e73b
, so let’s try
this:
@@ -2317,7 +2303,7 @@ OUTPUT<
--- a/guacamole.md
+++ b/guacamole.md
@@ -1,3 +1,7 @@
- # Gucamole
+ # Guacamole
## Ingredients
+* avocado
+* lime
@@ -2342,18 +2328,17 @@ OUTPUT<
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
- (use "git checkout -- <file>..." to discard changes in working directory)
-
+ (use "git restore <file>..." to discard changes in working directory)
modified: guacamole.md
no changes added to commit (use "git add" and/or "git commit -a")
We can put things back the way they were by using
-git checkout
:
+git restore
:
@@ -2366,15 +2351,15 @@ OUTPUT<
* salt
## Instructions
-As you might guess from its name, git checkout
checks
-out (i.e., restores) an old version of a file. In this case, we’re
-telling Git that we want to recover the version of the file recorded in
-HEAD
, which is the last saved commit. If we want to go back
-even further, we can use a commit identifier instead:
+As you might guess from its name, git restore
restores
+an old version of a file. By default, it recovers the version of the
+file recorded in HEAD
, which is the last saved commit. If
+we want to go back even further, we can use a commit identifier instead,
+using -s
option:
BASH
@@ -2397,97 +2382,44 @@ BASHOUTPUT
On branch main
-Changes to be committed:
- (use "git reset HEAD <file>..." to unstage)
-
+Changes not staged for commit:
+ (use "git add <file>..." to update what will be committed)
+ (use "git restore <file>..." to discard changes in working directory)
modified: guacamole.md
+
+no changes added to commit (use "git add" and/or "git commit -a")
-Notice that the changes are currently in the staging area. Again, we
-can put things back the way they were by using
-git checkout
:
+Notice that the changes are not currently in the staging area, and
+have not been committed. If we wished, we can put things back the way
+they were at the last commit by using git restore
to
+overwrite the working copy with the last committed version:
-
-
-
-
-
-Don’t Lose Your HEAD
-
-Above we used
-
-to revert guacamole.md
to its state after the commit
-f22b25e
. But be careful! The command checkout
-has other important functionalities and Git will misunderstand your
-intentions if you are not accurate with the typing. For example, if you
-forget guacamole.md
in the previous command.
-
-ERROR
+OUTPUT
-Note: checking out 'f22b25e'.
-
-You are in 'detached HEAD' state. You can look around, make experimental
-changes and commit them, and you can discard any commits you make in this
-state without impacting any branches by performing another checkout.
-
-If you want to create a new branch to retain commits you create, you may
-do so (now or later) by using -b with the checkout command again. Example:
-
- git checkout -b <new-branch-name>
-
-HEAD is now at f22b25e Create a template for recipe
-
-The “detached HEAD” is like “look, but don’t touch” here, so you
-shouldn’t make any changes in this state. After investigating your
-repo’s past state, reattach your HEAD
with
-git checkout main
.
-
-
+# Guacamole
+## Ingredients
+* avocado
+* lime
+* salt
+## Instructions
It’s important to remember that we must use the commit number that
identifies the state of the repository before the change we’re
trying to undo. A common mistake is to use the number of the commit in
which we made the change we’re trying to discard. In the example below,
we want to retrieve the state from before the most recent commit
-(HEAD~1
), which is commit f22b25e
:
-So, to put it all together, here’s how Git works in cartoon form:
+(HEAD~1
), which is commit f22b25e
. We use the
+.
to mean all files:
+So, to put it all together, here’s how Git works in cartoon form:
-
-
-
-
-Simplifying the Common Case
-
-If you read the output of git status
carefully, you’ll
-see that it includes this hint:
-
-As it says, git checkout
without a version identifier
-restores files to the state saved in HEAD
. The double dash
---
is needed to separate the names of the files being
-recovered from the command itself: without it, Git would try to use the
-name of the file as the commit identifier.
-
-
-
-The fact that files can be reverted one by one tends to change the
+
The fact that files can be reverted one by one tends to change the
way people organize their work. If everything is in one large document,
it’s hard (but not impossible) to undo changes to the introduction
without also undoing changes made later to the conclusion. If the
@@ -2508,10 +2440,10 @@
Recovering Older Versions of a File
Git! Which commands below will let her recover the last committed
version of her Python script called data_cruncher.py
?
-$ git checkout HEAD
-$ git checkout HEAD data_cruncher.py
-$ git checkout HEAD~1 data_cruncher.py
-$ git checkout <unique ID of last commit> data_cruncher.py
+$ git restore
+$ git restore data_cruncher.py
+$ git restore -s HEAD~1 data_cruncher.py
+$ git restore -s <unique ID of last commit> data_cruncher.py
Both 2 and 4
@@ -2525,7 +2457,7 @@ Show me the solution
The answer is (5)-Both 2 and 4.
-The checkout
command restores files from the repository,
+
The restore
command restores files from the repository,
overwriting the files in your working directory. Answers 2 and 4 both
restore the latest version in the repository of the
file data_cruncher.py
. Answer 2 uses HEAD
to
@@ -2534,15 +2466,9 @@
Show me the solution
Answer 3 gets the version of data_cruncher.py
from the
commit before HEAD
, which is NOT what we
wanted.
-Answer 1 can be dangerous! Without a filename,
-git checkout
will restore all files in the
-current directory (and all directories below it) to their state at the
-commit specified. This command will restore
-data_cruncher.py
to the latest commit version, but it will
-also restore any other files that are changed to that version,
-erasing any changes you may have made to those files! As discussed
-above, you are left in a detached HEAD
state, and
-you don’t want to be there.
+Answer 1 results in an error. You need to specify a file to restore.
+If you want to restore all files you should use
+git restore .
@@ -2561,10 +2487,10 @@ Reverting a Commit
git revert [erroneous commit ID]
will create a new commit
that reverses the erroneous commit.
The command git revert
is different from
-git checkout [commit ID]
because git checkout
-returns the files not yet committed within the local repository to a
-previous state, whereas git revert
reverses changes
-committed to the local and project repositories.
+git restore -s [commit ID] .
because
+git restore
returns the files not yet committed within the
+local repository to a previous state, whereas git revert
+reverses changes committed to the local and project repositories.
Below are the right steps and explanations for Jennifer to use
git revert
, what is the missing command?
@@ -2573,7 +2499,7 @@ Reverting a Commit
e.g. 0b1d055).
git revert [commit ID]
Type in the new commit message.
-Save and close
+Save and close.
@@ -2603,33 +2529,33 @@ Show me the solution
Understanding Workflow and History
What is the output of the last command in
-
+
BASH
-$ cd recipes
-$ echo "I like tomatos, therefore I like ketchup" > ketchup.md
-$ git add ketchup.md
-$ echo "ketchup enchances pasta dishes" > ketchup.md
-$ git commit -m "my opinions about the red sauce"
-$ git checkout HEAD ketchup.md
-$ cat ketchup.md # this will print the content of ketchup.md on screen
+$ cd recipes
+$ echo "I like tomatoes, therefore I like ketchup" > ketchup.md
+$ git add ketchup.md
+$ echo "ketchup enhances pasta dishes" >> ketchup.md
+$ git commit -m "My opinions about the red sauce"
+$ git restore ketchup.md
+$ cat ketchup.md # this will print the content of ketchup.md on screen
-
OUTPUT
- ketchup enchances pasta dishes
+ ketchup enhances pasta dishes
-
OUTPUT
- I like tomatos, therefore I like ketchup
+ I like tomatoes, therefore I like ketchup
-
OUTPUT
- I like tomatos, therefore I like ketchup
- ketchup enchances pasta dishes
+ I like tomatoes, therefore I like ketchup
+ ketchup enhances pasta dishes
-
OUTPUT
@@ -2653,18 +2579,18 @@ Show me the solution
git add ketchup.md
places the current version of
ketchup.md
into the staging area. not the version in the
staging area.
-
So, when git commit -m "my opinions about the red sauce"
+
So, when git commit -m "My opinions about the red sauce"
is executed, the version of ketchup.md
committed to the
repository is the one from the staging area and has only one line.
At this time, the working copy still has the second line (and
git status
will show that the file is modified).
-However, git checkout HEAD ketchup.md
replaces the working
-copy with the most recently committed version of
-ketchup.md
. So, cat ketchup.md
will output
+However, git restore ketchup.md
replaces the working copy
+with the most recently committed version of ketchup.md
. So,
+cat ketchup.md
will output
OUTPUT
-I like tomatos, therefore I like ketchup
+I like tomatoes, therefore I like ketchup
@@ -2695,11 +2621,11 @@ Checking Understanding of
Getting Rid of Staged Changes
-git checkout
can be used to restore a previous commit
+
git restore
can be used to restore a previous commit
when unstaged changes have been made, but will it also work for changes
that have been staged but not committed? Make a change to
guacamole.md
, add that change using git add
,
-then use git checkout
to see if you can remove your
+then use git restore
to see if you can remove your
change.
@@ -2711,41 +2637,34 @@ Show me the solution
-After adding a change, git checkout
can not be used
+
After adding a change, git restore
can not be used
directly. Let’s look at the output of git status
:
OUTPUT
On branch main
Changes to be committed:
- (use "git reset HEAD <file>..." to unstage)
-
+ (use "git restore --staged <file>..." to unstage)
modified: guacamole.md
Note that if you don’t have the same output you may either have
forgotten to change the file, or you have added it and
committed it.
-Using the command git checkout -- guacamole.md
now does
-not give an error, but it does not restore the file either. Git
-helpfully tells us that we need to use git reset
first to
+
Using the command git restore guacamole.md
now does not
+give an error, but it does not restore the file either. Git helpfully
+tells us that we need to use git restore --staged
first to
unstage the file:
-
+
-
-OUTPUT
+
Now, git status
gives us:
+
+BASH
-Unstaged changes after reset:
-M guacamole.md
-
-
-Now, `git status` gives us:
-
-```bash
-$ git status
+$ git status
OUTPUT
@@ -2753,19 +2672,18 @@ OUTPUT<
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
- (use "git checkout -- <file>..." to discard changes in working directory)
-
+ (use "git git restore <file>..." to discard changes in working directory)
modified: guacamole.md
no changes added to commit (use "git add" and/or "git commit -a")
-This means we can now use git checkout
to restore the
+
This means we can now use git restore
to restore the
file to the previous commit:
-
+
OUTPUT
@@ -2794,28 +2712,28 @@ Explore and Summarize Histories
Recall that the git diff
command allows us to explore
one specific file, e.g., git diff guacamole.md
. We can
apply a similar idea here.
-
+
Unfortunately some of these commit messages are very ambiguous, e.g.,
update files
. How can you search through these files?
Both git diff
and git log
are very useful
and they summarize a different part of the history for you. Is it
possible to combine both? Let’s try the following:
-
+
You should get a long list of output, and you should be able to see
both commit messages and the difference between each commit.
Question: What does the following command do?
-
@@ -2831,7 +2749,7 @@ Key Points
-
git diff
displays differences between commits.
-
-
git checkout
recovers old versions of files.
+git restore
recovers old versions of files.
@@ -3380,7 +3298,7 @@ BASHremote for the local
repository. The home page of the repository on GitHub includes the URL
string we need to identify it:
-
Click on the ‘SSH’ link to change the protocol from HTTPS to SSH.
+Click on the ‘SSH’ link to change the protocol from HTTPS to SSH.
@@ -3391,13 +3309,11 @@ HTTPS vs. SSH
We use SSH here because, while it requires some additional
configuration, it is a security protocol widely used by many
applications. The steps below describe SSH at a minimum level for
-GitHub. A supplemental episode to this lesson discusses advanced setup
-and concepts of SSH and key pairs, and other material supplemental to
-git related SSH.
+GitHub.
-Copy that URL from the browser, go into the local
+
Copy that URL from the browser, go into the local
recipes
repository, and run this command:
BASH
@@ -3503,9 +3419,10 @@ OUTPUT<
3.1 Create an SSH key pair
-To create an SSH key pair Vlad uses this command, where the
+
To create an SSH key pair Alfredo uses this command, where the
-t
option specifies which type of algorithm to use and
--C
attaches a comment to the key (here, Vlad’s email):
+-C
attaches a comment to the key (here, Alfredo’s
+email):
BASH
@@ -3530,7 +3447,10 @@ OUTPUT<
Now, it is prompting Alfredo for a passphrase. Since he is using his
kitchen’s laptop that other people sometimes have access to, he wants to
create a passphrase. Be sure to use something memorable or save your
-passphrase somewhere, as there is no “reset my password” option.
+passphrase somewhere, as there is no “reset my password” option. Note
+that, when typing a passphrase on a terminal, there won’t be any visual
+feedback of your typing. This is normal: your passphrase will be
+recorded even if you see nothing changing on your screen.
OUTPUT
@@ -3613,13 +3533,12 @@ OUTPUT<
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDmRA3d51X0uu9wXek559gfn6UFNF69yZjChyBIU2qKI a.linguini@ratatouille.fr
Now, going to GitHub.com, click on your profile icon in the top right
-corner to get the drop-down menu. Click “Settings,” then on the settings
-page, click “SSH and GPG keys,” on the left side “Account settings”
-menu. Click the “New SSH key” button on the right side. Now, you can add
-the title (Alfredo uses the title “Alfredo’s Kitchen Laptop” so he can
-remember where the original key pair files are located), paste your SSH
-key into the field, and click the “Add SSH key” to complete the
-setup.
+corner to get the drop-down menu. Click “Settings”, then on the settings
+page, click “SSH and GPG keys”, on the left side “Access” menu. Click
+the “New SSH key” button on the right side. Now, you can add the title
+(Alfredo uses the title “Alfredo’s Kitchen Laptop” so he can remember
+where the original key pair files are located), paste your SSH key into
+the field, and click the “Add SSH key” to complete the setup.
Now that we’ve set that up, let’s check our authentication again from
the command line.
@@ -4221,7 +4140,7 @@ Review Changes
-
+
On the command line, the Collaborator can use
git fetch origin main
to get the remote changes into the
@@ -4467,9 +4386,9 @@
OUTPUT<
-You may need to tell git what to do
+You may need to tell Git what to do
-If you see the below in your output, git is asking what it should
+
If you see the below in your output, Git is asking what it should
do.
OUTPUT
@@ -4487,7 +4406,7 @@ OUTPUT<
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
-In newer versions of git it gives you the option of specifying
+
In newer versions of Git it gives you the option of specifying
different behaviours when a pull would merge divergent branches. In our
case we want ‘the default strategy’. To use this strategy run the
following command to select it as the default thing git should do.
@@ -4714,7 +4633,7 @@ Conflicts on Non-textual files
-
+
Let’s try it. Suppose Alfredo takes a picture of its guacamole and
calls it guacamole.jpg
.
@@ -4957,7 +4876,7 @@ A Typical Work Session
-
+