Skip to content
Open
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
66 changes: 57 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This is a repo to help you practice diffing!
To get started:

1. Fork this repo.
⚠️ IMPORTANT: Fork all branches. Not just `main`
⚠️ IMPORTANT: Fork all branches. Not just `main`
2. Clone your forked repo:

```bash
Expand All @@ -23,11 +23,12 @@ A diff is a specific file format that tells you the difference between lines in
$$
A = B \circ \text{Apply}(\text{Diff}(A, B))
$$

That is, the difference between A and B can allow A to be transformed into B and vice versa using a function that **applies** said difference.

Let's now look at an example diff:

```diff
````diff
diff --git a/README.md b/README.md ①
index 7f35690..14cf26a 100644 ②
--- a/README.md ③
Expand All @@ -45,12 +46,11 @@ This is a repo to help you practice diffing!

-Follow these instructions c.a.r.e.f.u.l.l.y. ⑦
+Follow these instructions carefully.
```
````

Fill in what each of the elements of the diff mean (if you are not sure just guess!):


**①**
**①**
Shows this is a diff in git format. It is followed by the file names being compared. The `a/` and `b/` 'folders' are like virtual folders that usually represent different versions with the newer version being b/ and the older version being a/.

**②**
Expand All @@ -71,6 +71,29 @@ In this example, one line is replaced and 3 additional lines are added in the ne
**⑦**:
In this case there is a common whitespace in both files bollowed by a change in one line (notice that only one word changed, but the diff does not indicate this). Notice also that this is redundant given the next line!

---

**①**:
Shows the difference between README in a and b folders

**②**:
The hashes of both compared commits

**③**:
Shows in which way each of the files was changed (something was added/deleted)

**④**:
Between what lines changes was done

**⑤**:
Line wasn`t changed

**⑥**:
Three lines were added at that place

**⑦**:
c.a.r.e.f.u.l.l.y. was changed into the carefully

Notice that the diff above only showed different **lines** in the file. Including whitespaces. We can also highlight changes at the word level with the --word-diff option:

```diff
Expand Down Expand Up @@ -106,18 +129,31 @@ git diff --word-diff
```

## Stashing
>

<<<<<<< Updated upstream

> Make sure you attempted to fill in your explanation above!

Guess what!? Your lecturer has also got an answer to these questions! They are in another branch though!
# Guess what!? Your lecturer has also got an answer to these questions! They are in another branch though!

> Make sure you attempted to fill in your explanation above!

Guess what!? Your lecturer has also got an answer to these questions! They are in another branch, though.

> > > > > > > Stashed changes

Let's go check them out so we can decide whether we like them better. Run the following git commad:

```bash
git switch answers
```

<<<<<<< Updated upstream
Did it work? If it did it just means you didn't follow the instructions carefully!
=======
Did it work? If it did, it just means you didn't follow the instructions carefully!

> > > > > > > Stashed changes

If it didn't work, you have yourself a quandary:

Expand All @@ -129,7 +165,12 @@ Bet you didn't expect an existential crisis learning git (well, you should!).

Lucky for you, there is one quality of life option we didn't mention: `git stash`.

This command *stashes* your changes safely away so you can come back to them later. It is like a commit to the "not sure what to do with this yet" branch.
<<<<<<< Updated upstream
This command _stashes_ your changes safely away so you can come back to them later. It is like a commit to the "not sure what to do with this yet" branch.
=======
This command _stashes_ your changes safely away so you can return to them later. It is like a commit to the "not sure what to do with this yet" branch.

> > > > > > > Stashed changes

So let's do that:

Expand All @@ -147,6 +188,13 @@ pop goes the stash and your changes are back (and no longer on the stash).

Okay, stash them again, and then switch to the `answers` branch

<<<<<<< Updated upstream
Go ahead. Look at the answers. Notice that some are probably better than yours, some are worse. You want to merge your stashed changes with the current changes. You can do this in this branch (simply pop the stash here) or you can merge the answers into main and then pop your stash. Either way, this time popping the stash will be a bit more complicated because there are changes in the same file that you have made and that your lecturer has made.

So you will have a conflict like any other merge conflict. But by now you are a pro at this! So go ahead, pop the stash and resolve the conflict.
# So you will have a conflict like any other merge conflict. But by now you are a pro at this! So go ahead, pop the stash and resolve the conflict.

Go ahead. Look at the answers. Notice that some are probably better than yours, and some are worse. You want to merge your stashed changes with the current changes. You can do this in this branch (simply pop the stash here), or you can merge the answers into main and then pop your stash. Either way, this time, popping the stash will be a bit more complicated because there are changes in the same file that you have made and that your lecturer has made.

So you will have a conflict like any other merge conflict. But by now, you are a pro at this! So go ahead, pop the stash and resolve the conflict.

> > > > > > > Stashed changes