Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify to not commit proposed change #904

Merged
merged 3 commits into from
May 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 66 additions & 2 deletions _episodes/05-history.md
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,72 @@ moving backward and forward in time becomes much easier.
>
> `git checkout` 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 `mars.txt`, add that change, and use `git checkout` to see if
> you can remove your change.
> Make a change to `mars.txt`, add that change using `git add`,
> then use `git checkout` to see if you can remove your change.
> > ## Solution
> > After adding a change, `git checkout` can not be used directly.
> > Let's look at the output of `git status`:
> > ~~~
> > On branch main
> > Changes to be committed:
> > (use "git reset HEAD <file>..." to unstage)
> >
> > modified: mars.txt
> >
> > ~~~
> > {: .output}
> >
> > 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 -- mars.txt` 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 unstage the file:
> > ~~~
> > $ git reset HEAD mars.txt
> > ~~~
> > {: .language-bash}
> >
> > ~~~
> > Unstaged changes after reset:
> > M mars.txt
> > ~~~
> > {: .output}
> >
> > Now, `git status` gives us:
> > ~~~
> > $ git status
> > ~~~
> > {: .language-bash}
> >
> > ~~~
> > 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)
> >
> > modified: mars.txt
> >
> > no changes added to commit (use "git add" and/or "git commit -a")
> > ~~~
> > {: .output}
> >
> > This means we can now use `git checkout` to restore the file
> > to the previous commit:
> > ~~~
> > $ git checkout -- mars.txt
> > $ git status
> > ~~~
> > {: .language-bash}
> >
> > ~~~
> > On branch main
> > nothing to commit, working tree clean
> > ~~~
> > {: .output}
> {: .solution}
{: .challenge}

> ## Explore and Summarize Histories
Expand Down