Practice 5: Troubleshooting
By the end of this practice, you will know how to
- Manually resolve simple merge conflicts
- Use the
git blame
andgit bisect
tools to inspect history of files
Setup
This time, everybody will be contributing to the same repository. You will get access to a repository that was created for this practice. If you don't have access to push to the repository, write to the instructor.
Because we're working with a public repository and collaborating with others, let's enforce good practices and do all work in a separate branch. Make new commits as often as you think is useful and try to write informative commit messages.
- Clone the repository for this practice: https://github.com/Stopa/cse-prac5-troubleshooting
- Create a new branch, name it after yourself (your first name) and switch to it. Make sure you are on your own branch, not on
master
- Create a new directory with your first name and create a file
answers.txt
in it.
Tracing changes
Use the tools introduced in lecture to answer the following questions and write the answers to your answers.txt
file:
- How many commits have been made in this repository?
- What is the SHA-1 hash of the last commit that changed the line containing the
<title>
tag in theindex.html
file? - How many different commits can you see in the
blame
output forindex.html
? - All of the lines in
style.css
have stayed the same since the beginning of the repository, except one. What is that line?
Finding the source of an issue
The repository contains a file called image.png
. It is a simple rectangle. At the latest state of the repository, the image is light purple, but at the beginning it was black. Use the git bisect
to find the SHA-1 of the first commit where the image was not black
- Use
git bisect start
to start bisecting. Usegit bisect bad
to tell Git that current state is "broken" (image is not black). - Use
git bisect good <hash>
with the SHA-1 hash of the first commit in the repository (usegit history
alias introduced previously,git log
or some other tool to view repository history) to tell Git that the first commit was "good" (image was black) - Git will check out a commit between those. Open
image.png
. If it's black, usegit bisect good
to say that at that state, the image was "good" (black). If it's not black, usegit bisect bad
to tell Git that at that point the image was already "bad" (not black). - Repeat the process until you find the first "bad" commit.
- Use
git bisect reset
to go to where you were you were before bisecting. - Write the SHA-1 hash of the first "bad" commit that you found into your
answers.txt
file.
Conflicts and resolutions
In this part, we create a situation similar to the example shown in lecture and solve the emerging conflict. Also everybody contributes to the same file, so for some people adding their name will create a conflict that they will have to solve (some lucky people may not need to deal with a conflict at that stage).
- Write your name on a new line in the
names.txt
file - Copy the
style.css
file to your own directory - Create a new branch (from your own branch, not from master)
- On the newly created branch, in file
style.css
that you copied to your directory, change the value of line 8 to be "margin: 20px 10px;" - Commit the changes and go back to the branch you created at the beginning of the practice and change the value of the same line to be "margin: 30px;"
- Merge the new branch into your branch. Resolve merge conflicts. You can choose to accept "ours", "theirs" or propose something different, as you see fit.
- Go back to
master
branch and dogit pull
- Merge your branch into
master
. On this step, there may be conflicts, because other students are also adding their names intonames.txt
file. If you encounter merge conflicts, resolve them in a way that doesn't delete anyone's name. - Push the changes to the repository. If Git tells says that you don't have access, talk to the instructor.