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
117 changes: 117 additions & 0 deletions 07_git_exercises/DanielBar_ex1/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# git_exercise

///Git Basics (commit, diff, branches)


1.In branch main, create a file called abc.txt containing the text 1 in it
cat .\abc.txt
echo 1 >> .\abc.txt
2. What is the color of file abc.txt in Pycharm's Project view?
Red
3. Add the file to the index (What is the color now?) and commit the changes (it's recommended to use git status in between steps)
git add .\abc.txt
git status
git commit
4. Append the line 2 to the end of abc.txt to change the state of this file in the working tree
echo 2 >> .\abc.txt
5. What is the color of file abc.txt in Pycharm's Project view?
Green
6. What is the command to show changes between the working tree to branch main?
git diff
7. Why does git diff --staged print nothing?
Since I haven't staged the changes after adding "2" to the file. The most recent addition was 1, which was indexed and commited. abc.txt with the line "2" is only on a working copy.
8. Why does git diff stage2 print error?
Since there was only one commit (after adding 1)
9. Add abc.txt to the index
git add .\abc.txt
10. What does git diff print? why?
11. What is the command to show changes between the index and branch main?
git diff HEAD/master
12. Append the line 3 to the end of abc.txt to change the state of this file in the working tree
echo 3 >> .\abc.txt
13. Would git diff --staged and git diff main commands print the same output? why?
They won't, because we haven't commited anything yet.
14. Why does abc.txt appear twice in the output of git status?
One in the new files, and one in the modified files list
15. Unstage the changes in your index and working tree (don't commit the changes)
git reset


///Resolve conflicts

1. List all existed branches this repo (print them)
git branch -a
bugfix/fix_readme_typo
bugfix/open_kibana_port
dev
feature/data_retention_policy
feature/elasticsearch_helm_chart
feature/lambda_migration
feature/upgrade_angular_version
feature/version1
feature/version2
* main
reset_question

2. Create a new branch called feature/lambda_migration and switch to this branch
git checkout -b feature/lambda_migration

3. Merge branch feature/version1 into feature/lambda_migration, observe the merged changes
git merge feature/version1
6. Are there any added commits for feature/lambda_migration after all merges were completed? what are those commits?
No



///Cherry picking

4. Which files have been added to your branch as a result of the commits cherry-picking?
app.py
config.json
5. Should you care about the order in which commits are picked? why?
The order matters since every change taking place on the branch is writing on top of the previous version, so merging a previous version can overrun a newer version



///Changes in working tree and switch branches


2. Create a new file called take.txt, write some lines in it and add it to the index (don't commit, only add). Now you have uncommitted changes in the working tree
cat take.txt
echo 'some' >> take.txt
echo 'lines' >> take.txt
echo 'in' >> take.txt
echo 'it' >> take.txt
git add .\take.txt
3. Checkout to dev, which error do you get? What are the two suggested approaches by git? Read about git stash command from the Official Git Docs. Feel clueless? ask your teacher to discuss git stash in class.
Your local changes to the following files would be overwritten by checkout:
take.txt
Please commit your changes or stash them before you switch branches.
Aborting
5. Does take.txt contain your changes when you're now in dev?
No
6. Checkout back to the branch you've come from, do you have your take.txt there? So what does Force Checkout do?
Force checkout is checking out (from one branch to another) even if the branch wasn't staged after changes took place in the local copy.

///RESET
1. This undone the last commit, painting the 10.txt in green (meaning...)
2.Painted 10.txt and 9.txt in red - the commannd resets the HEAD to the commit you select in both the history and undo the changes in the index.
3. HEAD is now at 8cfbede 7. use the “git reset” command with the “–hard” option and specify the HEAD. The purpose of the “git reset” command is to move the current HEAD to the commit specified (in this case, the HEAD itself, one commit before HEAD and so on)
4. Revert "6"

This reverts commit b4553e0871b7e1a6a175a5138c604faf37fa0064.

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch reset_question
# Changes to be committed:
# deleted: 6.txt
#
# Untracked files:
# 10.txt
# 9.txt


Last question -
HEAD~1 refers to the previous commit (not the one we just made, but the one before that)