Week 3 - Homework
This week, we are learning to use git diff
, use documentation, and resolve conflicts. The practical part of the homework requires you to answer 18.5 questions. Write the answers down. On paper or in a Google doc shared with us.
Instructions
Chapter 20
Skip the paragraph that starts with "In fact, Git’s notion of any specific version...".
Other than that, read the whole thing.
The paragraph you skipped contains incorrect information. I mean, it is correct in a very specific way but not in a way that is helpful for understanding git, in my opinion. So, here is the correct version:
Each commit contains complete versions of all files that have been added (in the sense of
git add
) up to the point when this commit was created withgit commit
.
Chapter 21-23 - skip, do this instead
Changes made on Friday, March 31 after the Office Hours
At the very beginning, the terminal needs to be open in one of the repo folders, not in the folder with all your git-course-related stuff.
Step 0. Added more information about cleaning the repo and instructions on what to do if that doesn't work.
Step 2. Reworded the question so that it is clear that it is not rhetorical.
Step 4. Added
--oneline
to the command so that the change is easier to see.Step 5. More explicit instructions.
Step 6. Made "week-3.txt" bold to emphasize that that is the name that should be used and not "week-3". Added "No question here." at the end.
Steps 7, 8, 9. Changed the order - it was incorrect before.
What is now Step 7. Made "the same name" bold to emphasize that the same name should be used.
What is now Step 9. Added "No question here." at the end.
Step 18. Changed the full stop at the end to a question mark to make the last sentence a question.
Open the terminal in one of the repositories that you created before.
0. Clean up the repo - run git fetch
and then delete/add/commit/pull/push until git status
tells you
Don't spend more than 10 minutes on this. If it doesn't work, just create a new repository on GitHub, create a text file there, edit and commit the file at least four commits with distinct messages, and then clone it to your computer, and open the Terminal in that repo's folder.
Run
git remote -v
. What is the first string in each line?That is the name of your remote - remote repository you push to and pull from. In our case, the remote is in GitHub. Most probably, yours is called
origin
- that's what git defaults to. How does git know that your local repository has this specific remote repository? What was the specific thing that you did that resulted in git learning that information?Run
git log --oneline
. What are the alphanumeric strings on the left?Run
git log --oneline -n 2
. What's changed compared to the previous output?Run
gh browse
in the terminal. If the terminal says that it doesn't know whatgh
means, go to GitHub setup in the prerequisites, find instructions for installing GitHub CLI, and install it.In your repository on GitHub, create a file called "week-3.txt", write "GitHub" in it, make an empty line at the end, and commit the file. No question here.
Run
git status
. Why does it tell you that everything is up-to-date?Run
git fetch
and thengit status
. What's changed?Back on your computer, create a file with the same name and with "<your-name>'s computer" inside the file, add an empty line at the end, and commit the file. No question here.
Run
git pull
. What is git complaining about?Open
week-3.txt
in an editor. What symbol does git use to delineate local and remote conflicting changes?Undo changes to your file since the last commit with
git restore -- week-3.txt
. Why doesn't git want to do that?Run
git restore --theirs
. Usecat week-3.txt
to see what's currently in the file. What did "theirs" refer to?Go to https://git-scm.com/, find documentation for
git restore
, and find out the way to do the opposite of what you did with the previous command. Docs for the corresponding option warn about--theirs
being confusing sometimes. What are those cases?Run
git status
again and find the command that aborts the merge. What is it? Run it.We didn't explicitly ask git to do any merging. It happened implicitly when we called pull. Read the documentation for
git pull
to answer the following two questions:git pull
is equivalent to running command X and thengit merge
- by default. What is the command X?What is the alternative to
git merge
?
Run
git pull --ff-only
and thengit status
. How is the output ofgit status
different from the output we got aftergit pull
eariler?Run
git pull
. Open "week-3.txt" in a text editor and clean it up so that it represents some reasonable result of merging. Add "week-3.txt", commit, and push. Rungh browse
again. What is the abbreviated SHA of the commit you just pushed?
Last updated