You've already forked devops-exercises
Rename exercises dir
Name it instead "topics" so it won't be strange if some topics included "exercises" directory.
This commit is contained in:
20
topics/git/solutions/branch_01_solution.md
Normal file
20
topics/git/solutions/branch_01_solution.md
Normal file
@@ -0,0 +1,20 @@
|
||||
## Branch 01 - Solution
|
||||
|
||||
```
|
||||
cd some_repository
|
||||
echo "master branch" > file1
|
||||
git add file1
|
||||
git commit -a -m "added file1"
|
||||
git checkout -b dev
|
||||
echo "dev branch" > file2
|
||||
git add file2
|
||||
git commit -a -m "added file2"
|
||||
```
|
||||
|
||||
Verify:
|
||||
|
||||
```
|
||||
git log (you should see two commits)
|
||||
git checkout master
|
||||
git log (you should see one commit)
|
||||
```
|
||||
10
topics/git/solutions/commit_01_solution.md
Normal file
10
topics/git/solutions/commit_01_solution.md
Normal file
@@ -0,0 +1,10 @@
|
||||
## Git Commit 01 - Solution
|
||||
|
||||
```
|
||||
mkdir my_repo && cd my_repo
|
||||
git init
|
||||
echo "hello_commit" > file
|
||||
git add file
|
||||
git commit -a -m "It's my first commit. Exciting!"
|
||||
git log
|
||||
```
|
||||
49
topics/git/solutions/squashing_commits.md
Normal file
49
topics/git/solutions/squashing_commits.md
Normal file
@@ -0,0 +1,49 @@
|
||||
## Git - Squashing Commits - Solution
|
||||
|
||||
|
||||
1. In a git repository, create a new file with the content "Mario" and commit the change
|
||||
|
||||
```
|
||||
git add new_file
|
||||
echo "Mario" -> new_file
|
||||
git commit -a -m "New file"
|
||||
```
|
||||
|
||||
2. Make change to the content of the file you just created so the content is "Mario & Luigi" and create another commit
|
||||
|
||||
```
|
||||
echo "Mario & Luigi" > new_file
|
||||
git commit -a -m "Added Luigi"
|
||||
```
|
||||
|
||||
3. Verify you have two separate commits - `git log`
|
||||
|
||||
4. Squash the two commits you've created into one commit
|
||||
|
||||
```
|
||||
git rebase -i HEAD~2
|
||||
```
|
||||
|
||||
You should see something similar to:
|
||||
|
||||
```
|
||||
pick 5412076 New file
|
||||
pick 4016808 Added Luigi
|
||||
```
|
||||
|
||||
Change `pick` to `squash`
|
||||
|
||||
|
||||
```
|
||||
pick 5412076 New file
|
||||
squash 4016808 Added Luigi
|
||||
```
|
||||
|
||||
Save it and provide a commit message for the squashed commit
|
||||
|
||||
### After you complete the exercise
|
||||
|
||||
Answer the following:
|
||||
|
||||
* What is the reason for squashing commits? - history becomes cleaner and it's easier to track changes without commit like "removed a character" for example.
|
||||
* Is it possible to squash more than 2 commits? - yes
|
||||
Reference in New Issue
Block a user