You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+48-3Lines changed: 48 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -170,14 +170,13 @@ For that, in the GitHub web interface for the pull request follow the steps:
170
170
./gh-reset-repo.sh
171
171
```
172
172
173
-
174
173
1. Create your own commits and pull requests.
175
174
Be creative.
176
175
177
176
Create at least one pull request with two commits.
178
177
Use the `Squash and merge` merge strategy.
179
178
180
-
## Understand`git merge` and `git rebase`
179
+
## Understanding`git merge` and `git rebase`
181
180
182
181
When working with multiple branches, we often need to bring changes from one branch into another.
183
182
The two most common ways to do this are:
@@ -487,7 +486,6 @@ They may contain the same changes, but they are rewritten commits.
487
486
* the result looks like the work happened in a straight line
488
487
* there is usually no merge commit
489
488
490
-
491
489
### Now you want to remove all the commits created during this rebase exercise.
492
490
493
491
After the rebase, the commits created during this exercise are still on `<your-rebase-branch-name>`, but they were rewritten on top of `main`.
@@ -527,6 +525,53 @@ If needed, delete `<your-rebase-branch-name>` as well:
527
525
git branch -D <your-rebase-branch-name>
528
526
```
529
527
528
+
## Checking your work with `git cherry` and `git diff`:
529
+
530
+
Let's take a quick look at two very useful commands for checking your work: `git diff` and `git cherry`.
531
+
532
+
First, make sure you're on the `main` branch. Use either `git status` or `git branch`. Now, let's create a new branch:
533
+
```console
534
+
git checkout -b <branch-name>
535
+
```
536
+
537
+
## `git diff` is used to see the changes you've made and what state they're in.
538
+
539
+
Go to `cpp-hello/hello.cpp` and change the message it prints. Now run
540
+
```console
541
+
git diff
542
+
```
543
+
and you should see the change you've just made. `git diff` with no arguments will show you your unstaged changes (as in: changes you haven't comitted yet).
544
+
545
+
To see the changes you've commited but haven't pushed, use:
546
+
```console
547
+
git diff --staged
548
+
```
549
+
It shouldn't show anything for now. Commit your change to `cpp-hello/hello.cpp` and run it again.
550
+
551
+
Then run `git diff`. Since your changes are now staged, it won't show anything.
552
+
553
+
The last use of `git diff` is to show the difference between branches. Using:
554
+
```console
555
+
git diff main
556
+
```
557
+
will show the difference between your current work and the `main` branch. `git diff --staged main` also works.
558
+
559
+
## `git cherry` shows the difference in commits between two branches.
560
+
561
+
Try running:
562
+
```console
563
+
git cherry main
564
+
```
565
+
You should see a hash that looks familiar. If it doesn't, try running `git diff main` again. Spoiler: it's the same commit (or at least it should be if you've done everything correctly).
566
+
567
+
`git cherry <second-branch>` shows you commits that your current branch has but `<second-branch>` doesn't have.
568
+
569
+
Remembering and recognizing hashes is hard though. Try running:
570
+
```console
571
+
git cherry -v main
572
+
```
573
+
This way, you can also see the commit message of the commits missing from `main`.
574
+
530
575
## Configure Merge Strategy
531
576
532
577
We want to configure Rebase and merge as the only merge strategy.
0 commit comments