Skip to content

Commit cf2cf33

Browse files
committed
update force-pull activity
1 parent aec5579 commit cf2cf33

File tree

20 files changed

+268
-190
lines changed

20 files changed

+268
-190
lines changed

00-assumptions.md/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
### Assumptions
2+
- Basic Git knowledge
3+
- enough to be dangerous
4+
5+
### Things to know
6+
7+
1. This will use `git reset`, so you should first check that:
8+
- The commits in question are _only local_.
9+
- There are no unintended files in your working or staging directory.
10+
11+
2. git lol is set for every exercise
12+
2. most activities start by CD'ing into the directory

01-committed-too-big/README.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
### Commit is too big
22

3-
How can I commit only part of a file in Git? (Or, revise commits where I committed too much?)
4-
5-
1. Run `. setup.sh`
6-
7-
Look at the files and history that's been created. You'll see that several files and a history have been created. We want to change the history so the commits are more logical.
8-
9-
First, we need to move those changes back into the working directory so we can re-stage and re-commit.
10-
11-
2. `git reset reset-here` to a certain commit, bringing the changes that should be broken up into the working directory.
12-
3. Use `git add -p` to be specific about how commits are formed. You can use `s` to split even further.
13-
4. When you're done with the activity, run `. reset.sh`.
3+
> That commit is too big. It should have been broken up into several commits.
4+
5+
1. Change directories into the activity file: `cd 01-committed-too-big`
6+
2. Run `. setup.sh`
7+
3. Look at the files and the history: `ls` and `git lol`
8+
3. `git reset reset-here` to a certain commit, bringing the changes that should be broken up into the working directory
9+
4. Use `git add -p` to be specific about how commits are formed. You can use `s` to split even further.
10+
5. When you're done with the activity, run `. reset.sh` and `cd ..`
Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
### Accidental Commit
22

3-
I committed to master instead of a branch!
3+
> I committed to master instead of a branch!
44
5-
This will use `git reset`, so you should first check that:
6-
- The commits in question are _only local_.
7-
- There are no unintended files in your working or staging directory.
8-
9-
#### Getting started
10-
1. Run `. setup.sh`.
11-
- This sets a local alias, `git lol`. Use `git lol` and `git status` to see the current state of your repository.
12-
2. Use `git reset` back to the last commit that was meant to be on master.
13-
- Normally, you could use `git reset origin/master`. For today, use the `reset-here` tag: `git reset reset-here`.
14-
- Use `git lol` and `git status` again.
15-
3. Create a new branch and checkout to it with `git checkout -b experiment`. (Your working and staging area will come with you!)
16-
4. Stage your changes, and make a commit.
17-
- :tada: Yay, the commit is now where it should be!
18-
5. Once you're finished, run `. reset.sh`.
5+
1. Change directories into the activity file: `cd 02-accidental-commit-to-master`
6+
2. Run `. setup.sh`
7+
3. Use `git lol` and `git status` to see the current state of your repository
8+
4. Reset back to the last commit that was meant to be on master: `git reset reset-here`
9+
- Alternatively, you could reset to `origin/master` also
10+
5. Use `git lol` and `git status` again
11+
6. Create a new branch and checkout to it with `git checkout -b experiment`
12+
- Notice your working and staging area will come with `HEAD`
13+
7. Stage your changes, and make a commit
14+
8. Once you're finished, run `. reset.sh` and `cd ..`

02-accidental-commit-to-master/experiment.md

Whitespace-only changes.

03-detached-head/README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
### I'm in a detached head state
22

3-
1. Run `. setup.sh`
3+
> Git says I'm in a "detached head state" and I don't know what to do.
44
55
A detached head state only means that your `HEAD` pointer is currently pointed _not_ to a branch.
66

7-
2. You can see this by typing `git lol` (an alias was set in the setup script)
8-
97
To fix this, to get your `HEAD` attached, you need to point to a branch. You can do this by checking out to an existing branch, or creating a new branch where you are.
108

11-
3. Let's create a new branch where we are with `git checkout -b more-work`
12-
13-
Now, you're no longer in a detached head state. You can continue working normally on your new branch.
14-
15-
4. Reset the activity with `. reset.sh`
9+
1. Change directories into the activity file: `cd 03-detached-head`
10+
2. Run `. setup.sh`
11+
3. See where your `HEAD` is pointing with `git lol`
12+
4. Let's create a new branch where we are with `git checkout -b more-work`
13+
- Now, you're no longer in a detached head state, and can continue working normally on your new branch
14+
5. Reset the activity with `. reset.sh` and `cd ..`

04-what-broke-this/README.md

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
### What broke my code?
22

3-
Something's been broken, but I don't know what commit broke it.
3+
> Something's been broken, but I don't know what commit broke it.
44
5-
There's a test in this directory, checking if any file is empty or not.
5+
There's a test in this directory, checking if any file is empty or not. This only _finds_ the commit introducing the break, it doesn't fix it at all.
66

7-
1. `ls`
8-
1. `. test.sh`
9-
10-
To get set up, run the scripts:
11-
12-
2. `. setup.sh`
13-
3. `. test.sh` to find something's broken
14-
15-
Before you can use bisect, you need to be in the root directory of the repository.
16-
17-
1. `cd ..`
18-
1. `. 04-what-broke-this/test.sh`
19-
1. `git bisect start`
20-
1. `git bisect bad HEAD`
21-
1. `git bisect good before-activity4`
22-
1. `. 04-what-broke-this/test.sh`
23-
1. `git bisect good` or `git bisect good`, depending on the results of the test
24-
1. Continue until it finds the commit
25-
1. `git bisect reset`
26-
1. `. 04-what-broke-this/reset.sh`
7+
1. Change directories into the activity file: `cd 04-what-broke-this`
8+
2. See the test with `ls`, and try it with `. test.sh`
9+
3. To get set up, run the scripts `. setup.sh`
10+
4. Use the test `. test.sh` to find if something's broken
11+
5. Before you can use bisect, you need to be in the root directory of the repository: `cd ..`
12+
6. Try the test again: `. 04-what-broke-this/test.sh`
13+
7. Begin the bisect: `git bisect start`
14+
8. Tell Git where the "broken" commit is: `git bisect bad HEAD`
15+
9. Tell Git where the last known "good" commit was: `git bisect good before-activity4`
16+
10. After Git moves your `HEAD` pointer to a different commit, try your test again: `04-what-broke-this/test.sh`
17+
11. Depending on the results of the test, type `git bisect good` or `git bisect good`
18+
12. Continue until Git finds the commit
19+
13. Exit the bisect: `git bisect reset`
20+
14. Reset the files: `. 04-what-broke-this/reset.sh`

05-merge-two-repos/README.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
### I want to merge two repositories
22

3-
1. Run the setup script: `. setup.sh`
4-
1. Add the other repository as a second remote: `git remote add other-repo https://github.com/brianamarie/another-repository.git`
5-
1. Before you try to merge, make sure you have all of the remote tracking branches for all remotes: `git fetch --all`
6-
1. Try to merge the two repositories: `git merge other-repo/master` and notice the error message.
7-
1. Since these two repositories have unrelated histories, we need to specify a particular type of merge: `git merge other-repo/master --allow-unrelated-histories`.
8-
9-
In practice, we would probably want to create a new repository to have the combined histories of both of the other repositories. Then, it would be best to archive the singular repositories.
3+
> There are two separate project repositories that should be in one repository, but they have unrelated histories.
104
11-
1. You can see the combined history with the alias `git lol`
5+
In practice, you might want to create a new repository to have the combined histories of both of the other repositories. Then, it would be best to archive the singular repositories.
126

13-
Reset the exercise.
14-
15-
1. `. reset.sh`
7+
1. Run the setup script: `. setup.sh`
8+
2. Add the other repository as a second remote: `git remote add other-repo https://github.com/brianamarie/another-repository.git` OR `. add-remote.sh`
9+
3. Before you try to merge, make sure you have all of the remote tracking branches for all remotes: `git fetch --all`
10+
4. Try to merge the two repositories: `git merge other-repo/master` and notice the error message.
11+
5. Since these two repositories have unrelated histories, we need to specify a particular type of merge: `git merge other-repo/master --allow-unrelated-histories`
12+
6. You can see the combined history with the alias `git lol`
13+
7. Reset the exercise: `. reset.sh` and `cd ..`

05-merge-two-repos/add-remote.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
git remote add other-repo https://github.com/brianamarie/another-repository.git

06-revert-merge/README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
### I want to undo a recursive merge (without GitHub)
22

3-
1. Run `. setup.sh`
4-
2. Look at the log, and take lineage of commits' parents into account: `git lol` (alias set during script)
5-
3. Identify which branch is the "parent" branch of the merge. (The branch you were on when you merged is the parent, so we will refer to it as "1".) The parent in this case is `md-files`. We want to revert the merge, and _keep_ the files that were originally on this branch, the markdown files.
6-
4. Identify the merge commit.
7-
5. Revert the merge commit: `git revert -m <parent> <commit>`.
3+
> A merge happened locally, and then I pushed. I'd like to revert the merge and maintain all of committed history.
84
9-
- ex: `git revert -m 1 cd4370f`
5+
When reverting a merge, Git wants to know about the "parent" commits. The branch you were on when you merged is the parent, so we will refer to it as "1".
106

7+
1. Run `. setup.sh`
8+
2. Look at the log, and take lineage of commits' parents into account: `git lol`
9+
3. Identify which branch is the "parent" branch of the merge, `md-files` in our case
10+
4. Identify the merge commit
11+
5. Revert the merge commit: `git revert -m <parent> <commit>`
12+
- ex: `git revert -m 1 cd4370f`
1113
6. Look at the files and the log: `git lol`, and `ls`
12-
7. Reset the activity: `. reset.sh`
14+
7. Reset the activity: `. reset.sh` and `cd ..`

07-forget-binary/README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
I committed a binary file a long time ago, how to make git forget about a file that was tracked but is now in .gitignore?
1+
### I need Git to ignore a binary file
2+
3+
> I committed a binary file a long time ago, how to make git forget about a file that was tracked but is now in .gitignore?
4+
5+
When files are defined in the `.gitignore` from the start, Git will always ignore them. But, if a file is already tracked by Git, adding the name to the `.gitignore` doesn't do any good.
26

37
1. Run `. setup.sh`, then notice your history and working directory
48
2. Create a `.gitignore` file in the _root directory_ of this repository
59
3. Add `test.img` to the `.gitignore` file
10+
4. Add and commit the `.gitignore` file
11+
4. Change directories back into this activity: `cd 07-forget-binary`
612
4. Change the big binary file `. change-binary.sh`
7-
5. Add and commit the large binary file.
8-
- What did you expect to happen? Git knows the file based on its similarity index, not by the name, so it's not untracking it at all.
9-
6. For Git to ignore a file that is already being tracked, you need to run: `git rm --cached <file>`.
10-
- It should be noted that in general you also will want to get rid of these files! Tune in to Lars' session later. :wink:
13+
5. Add and commit the binary file.
14+
- What did you expect to happen? Git knows the file based on its similarity index, not by the name, so it's still tracked.
15+
6. For Git to ignore a file that is already being tracked, you need to remove the cache: `git rm --cached test.img`
16+
17+
> Note: this does not remove the file from history, only from tracking and any _new_ commits.

0 commit comments

Comments
 (0)