update module2.ipynb
This commit is contained in:
parent
1678dec6ad
commit
ba3a7c7156
610
module2.ipynb
610
module2.ipynb
@ -1654,7 +1654,23 @@
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Study guide: Git branches and merging\n",
|
||||
"\n"
|
||||
"\n",
|
||||
"Now that you’ve learned about branches and merging, use this study guide as an easy reference for Git branching. This study guide gives a brief explanation of these useful commands along with a link to the Git documentation for each command. Keeping study guides like this one easily accessible can help you code more efficiently.\n",
|
||||
"\n",
|
||||
"| Command | Explanation & link |\n",
|
||||
"| --- | --- |\n",
|
||||
"| git branch | [$ git branch<svg aria-labelledby=\"cds-react-aria3604314262-:r1ko:-title\" fill=\"none\" focusable=\"false\" height=\"16\" role=\"img\" viewBox=\"0 0 20 20\" width=\"16\" class=\"css-8blerm\" id=\"cds-react-aria3604314262-:r1ko:\"><title id=\"cds-react-aria3604314262-:r1ko:-title\">Opens in a new tab</title></svg>](https://git-scm.com/docs/git-branch) can be used to list, create, or delete branches. |\n",
|
||||
"| git branch <name> | [$ git branch <name><svg aria-labelledby=\"cds-react-aria3604314262-:r1kq:-title\" fill=\"none\" focusable=\"false\" height=\"16\" role=\"img\" viewBox=\"0 0 20 20\" width=\"16\" class=\"css-8blerm\" id=\"cds-react-aria3604314262-:r1kq:\"><title id=\"cds-react-aria3604314262-:r1kq:-title\">Opens in a new tab</title></svg>](https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging) can be used to create a new branch in your repository. |\n",
|
||||
"| git branch -d <name> | [$ git branch -d <name><svg aria-labelledby=\"cds-react-aria3604314262-:r1ks:-title\" fill=\"none\" focusable=\"false\" height=\"16\" role=\"img\" viewBox=\"0 0 20 20\" width=\"16\" class=\"css-8blerm\" id=\"cds-react-aria3604314262-:r1ks:\"><title id=\"cds-react-aria3604314262-:r1ks:-title\">Opens in a new tab</title></svg>](https://git-scm.com/docs/git-branch#Documentation/git-branch.txt--D) can be used to delete a branch from your repository. |\n",
|
||||
"| git branch -D <name> | [$ git branch -D <branch><svg aria-labelledby=\"cds-react-aria3604314262-:r1ku:-title\" fill=\"none\" focusable=\"false\" height=\"16\" role=\"img\" viewBox=\"0 0 20 20\" width=\"16\" class=\"css-8blerm\" id=\"cds-react-aria3604314262-:r1ku:\"><title id=\"cds-react-aria3604314262-:r1ku:-title\">Opens in a new tab</title></svg>](https://git-scm.com/docs/git-branch#Documentation/git-branch.txt--D) forces a branch to be deleted. |\n",
|
||||
"| git checkout <branch> | [$ git checkout <branch><svg aria-labelledby=\"cds-react-aria3604314262-:r1l0:-title\" fill=\"none\" focusable=\"false\" height=\"16\" role=\"img\" viewBox=\"0 0 20 20\" width=\"16\" class=\"css-8blerm\" id=\"cds-react-aria3604314262-:r1l0:\"><title id=\"cds-react-aria3604314262-:r1l0:-title\">Opens in a new tab</title></svg>](https://git-scm.com/docs/git-checkout) switches your current working branch. |\n",
|
||||
"| git checkout -b <new-branch> | [$ git checkout -b <new-branch><svg aria-labelledby=\"cds-react-aria3604314262-:r1l2:-title\" fill=\"none\" focusable=\"false\" height=\"16\" role=\"img\" viewBox=\"0 0 20 20\" width=\"16\" class=\"css-8blerm\" id=\"cds-react-aria3604314262-:r1l2:\"><title id=\"cds-react-aria3604314262-:r1l2:-title\">Opens in a new tab</title></svg>](https://git-scm.com/docs/git-checkout#Documentation/git-checkout.txt--bltnewbranchgt) creates a new branch and makes it your current working branch. |\n",
|
||||
"| git merge <branch> | [$ git merge <branch><svg aria-labelledby=\"cds-react-aria3604314262-:r1l4:-title\" fill=\"none\" focusable=\"false\" height=\"16\" role=\"img\" viewBox=\"0 0 20 20\" width=\"16\" class=\"css-8blerm\" id=\"cds-react-aria3604314262-:r1l4:\"><title id=\"cds-react-aria3604314262-:r1l4:-title\">Opens in a new tab</title></svg>](https://git-scm.com/docs/git-merge) joins changes from one branch into another branch. |\n",
|
||||
"| git merge --abort | [$ git merge --abort<svg aria-labelledby=\"cds-react-aria3604314262-:r1l6:-title\" fill=\"none\" focusable=\"false\" height=\"16\" role=\"img\" viewBox=\"0 0 20 20\" width=\"16\" class=\"css-8blerm\" id=\"cds-react-aria3604314262-:r1l6:\"><title id=\"cds-react-aria3604314262-:r1l6:-title\">Opens in a new tab</title></svg>](https://git-scm.com/docs/git-merge) can only be used after merge conflicts. This command will abort the merge and try to go back to the pre-merge state. |\n",
|
||||
"| git log --graph | [$ git log --graph <svg aria-labelledby=\"cds-react-aria3604314262-:r1l8:-title\" fill=\"none\" focusable=\"false\" height=\"16\" role=\"img\" viewBox=\"0 0 20 20\" width=\"16\" class=\"css-8blerm\" id=\"cds-react-aria3604314262-:r1l8:\"><title id=\"cds-react-aria3604314262-:r1l8:-title\">Opens in a new tab</title></svg>](https://git-scm.com/book/en/v2/Git-Basics-Viewing-the-Commit-History)prints an ASCII graph of the commit and merge history. |\n",
|
||||
"| git log --oneline | [$ git log --oneline<svg aria-labelledby=\"cds-react-aria3604314262-:r1la:-title\" fill=\"none\" focusable=\"false\" height=\"16\" role=\"img\" viewBox=\"0 0 20 20\" width=\"16\" class=\"css-8blerm\" id=\"cds-react-aria3604314262-:r1la:\"><title id=\"cds-react-aria3604314262-:r1la:-title\">Opens in a new tab</title></svg>](https://git-scm.com/book/en/v2/Git-Basics-Viewing-the-Commit-History) prints each commit on a single line. |\n",
|
||||
"\n",
|
||||
"Keep this table handy while you are getting comfortable using Git branches and merging. Now, it’s time to put your newfound knowledge of Git branches and merging to use!"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -1662,7 +1678,24 @@
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Glossary terms from module 2\n",
|
||||
"\n"
|
||||
"\n",
|
||||
"## **Terms and definitions from Module 2**\n",
|
||||
"\n",
|
||||
"**Branch:** A pointer to a particular commit, representing an independent line of development in a project\n",
|
||||
"\n",
|
||||
"**Commit ID:** An identifier next to the word commit in the log\n",
|
||||
"\n",
|
||||
"**Fast-forward merge:** A merge when all the commits in the checked out branch are also in the branch that's being merged\n",
|
||||
"\n",
|
||||
"**Head:** This points to the top of the branch that is being used\n",
|
||||
"\n",
|
||||
"**Master:** The default branch that Git creates for when a new repository initialized, commonly used to place the approved pieces of a project\n",
|
||||
"\n",
|
||||
"**Merge conflict:** This occurs when the changes are made on the same part of the same file, and Git won't know how to merge those changes\n",
|
||||
"\n",
|
||||
"**Rollback:** The act of reverting changes made to software to a previous state \n",
|
||||
"\n",
|
||||
"**Three-way merge:** A merge when the snapshots at the two branch tips with the most recent common ancestor, the commit before the divergence"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -1670,15 +1703,570 @@
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Exemplar: Merging Branches in Git\n",
|
||||
"\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# \n",
|
||||
"\n"
|
||||
"\n",
|
||||
"## Introduction\n",
|
||||
"\n",
|
||||
"In the previous lab, you used your knowledge of Git and Git commit history to check out an existing repo and make some changes to it. You also tested what you learned about rolling back commits after bad changes in order to fix a script in the repo and run it to produce the correct output.\n",
|
||||
"\n",
|
||||
"This exemplar is a walkthrough of the previous Qwiklab activity, including detailed instructions and solutions. You may use this exemplar if you were unable to complete the lab and/or you need extra guidance in competing lab tasks. You may also refer to this exemplar to prepare for the graded quiz in this module.\n",
|
||||
"\n",
|
||||
"## Explore repository\n",
|
||||
"\n",
|
||||
"There is a Git repository named food-scripts consisting of a couple of food-related Python scripts.\n",
|
||||
"\n",
|
||||
"Navigate to the repository using the following command:\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"cd ~/food\\-scripts\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"Now, list the files using the ls command. There are three files named **favorite\\_foods.log**, **food\\_count.py**, and **food\\_question.py**.\n",
|
||||
"\n",
|
||||
"**Output:**\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"favorite\\_foods.log food\\_count.py food\\_question.py\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"Let's explore each file. Use the cat command to view each file.\n",
|
||||
"\n",
|
||||
"1\\. **favorite\\_foods.log**: This file consists of a list of food items. You can view it using the following command:\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"cat favorite\\_foods.log\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"**Output:**\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"pie\n",
|
||||
"\n",
|
||||
"burgers\n",
|
||||
"\n",
|
||||
"pizza\n",
|
||||
"\n",
|
||||
"pie\n",
|
||||
"\n",
|
||||
"tacos\n",
|
||||
"\n",
|
||||
"fried chicken\n",
|
||||
"\n",
|
||||
"spaghetti\n",
|
||||
"\n",
|
||||
"rice\n",
|
||||
"\n",
|
||||
"cake\n",
|
||||
"\n",
|
||||
"broccoli\n",
|
||||
"\n",
|
||||
"cake\n",
|
||||
"\n",
|
||||
"cereal\n",
|
||||
"\n",
|
||||
"salad\n",
|
||||
"\n",
|
||||
"avocados\n",
|
||||
"\n",
|
||||
"burgers\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"2\\. **food\\_count.py**: This script returns a list of each food and the number of times the food appeared in the favorite\\_foods.log file.\n",
|
||||
"\n",
|
||||
"Let's execute the script food\\_count.py:\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"./food\\_count.py\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"**Output:**\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"rice, 12\n",
|
||||
"\n",
|
||||
"burgers, 10\n",
|
||||
"\n",
|
||||
"fried chicken, 9\n",
|
||||
"\n",
|
||||
"pie, 8\n",
|
||||
"\n",
|
||||
"pizza, 7\n",
|
||||
"\n",
|
||||
"salad, 7\n",
|
||||
"\n",
|
||||
"tacos, 6\n",
|
||||
"\n",
|
||||
"avocados, 6\n",
|
||||
"\n",
|
||||
"spaghetti, 5\n",
|
||||
"\n",
|
||||
"broccoli, 5\n",
|
||||
"\n",
|
||||
"ice cream, 5\n",
|
||||
"\n",
|
||||
"bananas, 5\n",
|
||||
"\n",
|
||||
"fish, 4\n",
|
||||
"\n",
|
||||
"cake, 3\n",
|
||||
"\n",
|
||||
"cereal, 3\n",
|
||||
"\n",
|
||||
"strawberries, 3\n",
|
||||
"\n",
|
||||
"watermelon, 2\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"3\\. **food\\_question.py**: This prints a list of foods and prompts the user to enter one of those foods as their favorite. It then returns an answer of how many others in the list like that same food.\n",
|
||||
"\n",
|
||||
"Run the following command to see the output of food\\_question.py script:\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"./food\\_question.py\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"**Output:**\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"Traceback (most recent call last):\n",
|
||||
"\n",
|
||||
" File \"./food\\_question.py\", line 10, in <module>\n",
|
||||
"\n",
|
||||
" if item not in counter:\n",
|
||||
"\n",
|
||||
"NameError: name 'item' is not defined\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"Uh-oh, this gives us an error. One of your colleagues reports that this script was working fine until the most recent commit. We'll be fixing this error later during the lab.\n",
|
||||
"\n",
|
||||
"## Understanding the repository\n",
|
||||
"\n",
|
||||
"Let's use the following Git operations to understand the workflow of the repository:\n",
|
||||
"\n",
|
||||
"- git status\n",
|
||||
"- git log\n",
|
||||
"- git branch\n",
|
||||
"\n",
|
||||
"**Git status:** This displays paths that have differences between the index file and the current HEAD commit; paths that have differences between the working tree and the index file; and paths in the working tree that are not tracked by Git. You can view the status of the working tree using the command: **\\[git status\\]**\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"git status\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"You can now view the status of the working tree.\n",
|
||||
"\n",
|
||||
"**Git log:** This lists the commits done in the repository in reverse chronological order; that is, the most recent commits show up first. This command lists each commit with its SHA-1 checksum, the author's name and email, date, and the commit message.\n",
|
||||
"\n",
|
||||
"You can see logs by using the following command:\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"git log\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"**Output:**\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"commit 21cf376832fa6eace35c0bf9e4bae4a3400452e9 (HEAD -> master)\n",
|
||||
"\n",
|
||||
"Author: Alex Cooper <alex\\_cooper@gmail.com>\n",
|
||||
"\n",
|
||||
"Date: Wed Jan 8 14:09:39 2020 +0530\n",
|
||||
"\n",
|
||||
" Rename item variable to food\\_item.\n",
|
||||
"\n",
|
||||
"commit b8d00e33237b24ea1480c363edd972cf4b49eedf\n",
|
||||
"\n",
|
||||
"Author: Alex Cooper <alex\\_cooper@gmail.com>\n",
|
||||
"\n",
|
||||
"Date: Wed Jan 8 14:08:35 2020 +0530\n",
|
||||
"\n",
|
||||
" Added file food\\_question.py that returns how many others in the list like that same food.\n",
|
||||
"\n",
|
||||
"commit 8d5a3189b88d273ef08286e5074b5e38d616da21\n",
|
||||
"\n",
|
||||
"Author: Alex Cooper <alex\\_cooper@gmail.com>\n",
|
||||
"\n",
|
||||
"Date: Wed Jan 8 14:07:15 2020 +0530\n",
|
||||
"\n",
|
||||
" Added file food\\_count.py that returns a list of each food and the number of times each food appears in favorite\\_foods.log file.\n",
|
||||
"\n",
|
||||
"commit 0a202e03e0356d2b5c323e51905d3d06e5e2d0ed\n",
|
||||
"\n",
|
||||
"Author: Alex Cooper <alex\\_cooper@gmail.com>\n",
|
||||
"\n",
|
||||
"Date: Wed Jan 8 14:06:21 2020 +0530\n",
|
||||
"\n",
|
||||
" Added file favorite\\_foods.log that contains list of foods.\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"**Git branch:** Branches are a part of the everyday development process on the master branch. Git branches effectively function as a pointer to a snapshot of your changes. When you want to add a new feature or fix a bug, no matter how big or small, you spawn a new branch to encapsulate your changes. This makes it difficult for unstable code to get merged into the main codebase.\n",
|
||||
"\n",
|
||||
"### Configure Git\n",
|
||||
"\n",
|
||||
"Before we move forward with the lab, let's configure Git. Git uses a username to associate commits with an identity. It does this by using the **git config** command. Set the Git username with the following command:\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"git config user.name \"Name\"\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"Replace **Name** with your name. Any future commits you push to GitHub from the command line will now be represented by this name. You can even use **git config** to change the name associated with your Git commits. This will only affect future commits and won't change the name used for past commits.\n",
|
||||
"\n",
|
||||
"Let's set your email address to associate them with your Git commits.\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"git config user.email \"user@example.com\"\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"Replace **user@example.com** with your email-id. Any future commits you now push to GitHub will be associated with this email address. You can also use **git config** to change the user email associated with your Git commits.\n",
|
||||
"\n",
|
||||
"## Add a new feature\n",
|
||||
"\n",
|
||||
"In this section, we'll be modifying the repository to add a new feature, without affecting the current iteration. This new feature is designed to improve the food count (from the file **food\\_count.py**) output. So, create a branch named **improve-output** using the following command:\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"git branch improve\\-output\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"Move to the improve-output branch from the master branch.\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"git checkout improve\\-output\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"Here, you can modify the script file without disturbing the existing code. Once modified and tested, you can update the master branch with a working code.\n",
|
||||
"\n",
|
||||
"Now, open food\\_count.py in the nano editor using the following command:\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"nano food\\_count.py\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"Add the line below before **printing for loop** in the food\\_count.py script:\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"print(\"Favourite foods, from most popular to least popular\")\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"Save the file by pressing **Ctrl-o**, the **Enter** key, and **Ctrl-x**.\n",
|
||||
"\n",
|
||||
"Then run the script food\\_count.py again to see the output:\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"./food\\_count.py\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"**Output:**\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"Favourite foods, from most popular to least popular\n",
|
||||
"\n",
|
||||
"rice, 12\n",
|
||||
"\n",
|
||||
"burgers, 10\n",
|
||||
"\n",
|
||||
"fried chicken, 9\n",
|
||||
"\n",
|
||||
"pie, 8\n",
|
||||
"\n",
|
||||
"pizza, 7\n",
|
||||
"\n",
|
||||
"salad, 7\n",
|
||||
"\n",
|
||||
"tacos, 6\n",
|
||||
"\n",
|
||||
"avocados, 6\n",
|
||||
"\n",
|
||||
"spaghetti, 5\n",
|
||||
"\n",
|
||||
"broccoli, 5\n",
|
||||
"\n",
|
||||
"ice cream, 5\n",
|
||||
"\n",
|
||||
"bananas, 5\n",
|
||||
"\n",
|
||||
"fish, 4\n",
|
||||
"\n",
|
||||
"cake, 3\n",
|
||||
"\n",
|
||||
"cereal, 3\n",
|
||||
"\n",
|
||||
"strawberries, 3\n",
|
||||
"\n",
|
||||
"watermelon, 2\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"After running the food\\_count.py script successfully, commit the changes from the improve-output branch by adding this script to the staging area using the following command:\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"git add food\\_count.py\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"Now, commit the changes you've done in the improve-output branch.\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"git commit \\-m \"Adding a line in the output describing the utility of food\\_count.py script\"\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"**Output:**\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"\\[improve\\-output 09b9ce4\\] Adding a line in the output describing the utility of food\\_count.py script\n",
|
||||
"\n",
|
||||
" 1 file changed, 1 insertion(+), 1 deletion(-)\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"## Fix the script\n",
|
||||
"\n",
|
||||
"In this section, we'll fix the script food\\_question.py, which displayed an error when executing it. You can run the file again to view the error.\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"./food\\_question.py\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"**Output:**\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"Traceback (most recent call last):\n",
|
||||
"\n",
|
||||
" File \"./food\\_question.py\", line 10, in <module>\n",
|
||||
"\n",
|
||||
" if item not in counter:\n",
|
||||
"\n",
|
||||
"NameError: name 'item' is not defined\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"This script gives us the error: **\"NameError: name 'item' is not defined\"** but your colleague says that the file was running fine before the most recent commit they did.\n",
|
||||
"\n",
|
||||
"In this case, we'll revert back the previous commit.\n",
|
||||
"\n",
|
||||
"For this, check the git log history so that you can revert back to the commit where it was working fine.\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"git log\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"**Output:**\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"commit 09b9ce441654a361477405d3eea785b3be5f8e8f (HEAD -> improve\\-output)\n",
|
||||
"\n",
|
||||
"Author: Name <user@example.com>\n",
|
||||
"\n",
|
||||
"Date: Thu Oct 12 10:48:08 2023 +0000\n",
|
||||
"\n",
|
||||
" Adding a line in the output describing the utility of food\\_count.py script\n",
|
||||
"\n",
|
||||
"commit 21cf376832fa6eace35c0bf9e4bae4a3400452e9 (master)\n",
|
||||
"\n",
|
||||
"Author: Alex Cooper <alex\\_cooper@gmail.com>\n",
|
||||
"\n",
|
||||
"Date: Wed Jan 8 14:09:39 2020 +0530\n",
|
||||
"\n",
|
||||
" Rename item variable to food\\_item.\n",
|
||||
"\n",
|
||||
"commit b8d00e33237b24ea1480c363edd972cf4b49eedf\n",
|
||||
"\n",
|
||||
"Author: Alex Cooper <alex\\_cooper@gmail.com>\n",
|
||||
"\n",
|
||||
"Date: Wed Jan 8 14:08:35 2020 +0530\n",
|
||||
"\n",
|
||||
" Added file food\\_question.py that returns how many others in the list like that same food.\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"Here, you'll see the commits in reverse chronological order and find the commit having **\"Rename item variable to food\\_item\"** as a commit message. Make sure to note the commit ID for this particular commit.\n",
|
||||
"\n",
|
||||
"To revert, use the following command:\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"git revert \\[commit\\-ID\\]\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"Replace \\[commit-ID\\] with the commit ID you noted earlier.\n",
|
||||
"\n",
|
||||
"This creates a new commit again. You can continue with the default commit message on the screen or add your own commit message.\n",
|
||||
"\n",
|
||||
"Then continue by clicking **Ctrl-o**, the **Enter** key, and **Ctrl-x**.\n",
|
||||
"\n",
|
||||
"Now, run food\\_question.py again and verify that it's working as intended.\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"./food\\_question.py\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"**Output:**\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"Select your favorite food below:\n",
|
||||
"\n",
|
||||
"pie\n",
|
||||
"\n",
|
||||
"burgers\n",
|
||||
"\n",
|
||||
"pizza\n",
|
||||
"\n",
|
||||
"tacos\n",
|
||||
"\n",
|
||||
"fried chicken\n",
|
||||
"\n",
|
||||
"spaghetti\n",
|
||||
"\n",
|
||||
"rice\n",
|
||||
"\n",
|
||||
"cake\n",
|
||||
"\n",
|
||||
"broccoli\n",
|
||||
"\n",
|
||||
"cereal\n",
|
||||
"\n",
|
||||
"salad\n",
|
||||
"\n",
|
||||
"avocados\n",
|
||||
"\n",
|
||||
"ice cream\n",
|
||||
"\n",
|
||||
"fish\n",
|
||||
"\n",
|
||||
"strawberries\n",
|
||||
"\n",
|
||||
"bananas\n",
|
||||
"\n",
|
||||
"watermelon\n",
|
||||
"\n",
|
||||
"Which of the foods above is your favorite? rice\n",
|
||||
"\n",
|
||||
"12 of your friends like rice as well!\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"## **Merge operation**\n",
|
||||
"\n",
|
||||
"Before merging the branch improve-output, switch to the master branch from the current branch improve-output branch using the command below:\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"git checkout master\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"Merge the branch improve-output into the master branch.\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"git merge improve\\-output\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"**Output:**\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"Updating 21cf376..70bd534\n",
|
||||
"\n",
|
||||
"Fast\\-forward\n",
|
||||
"\n",
|
||||
" food\\_count.py | 2 +-\n",
|
||||
"\n",
|
||||
" food\\_question.py | 2 +-\n",
|
||||
"\n",
|
||||
" 2 files changed, 2 insertions(+), 2 deletions(-)\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"Now, all your changes made in the improve-output branch are on the master branch.\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"./food\\_question.py\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"**Output:**\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"Select your favorite food below:\n",
|
||||
"\n",
|
||||
"pie\n",
|
||||
"\n",
|
||||
"burgers\n",
|
||||
"\n",
|
||||
"pizza\n",
|
||||
"\n",
|
||||
"tacos\n",
|
||||
"\n",
|
||||
"fried chicken\n",
|
||||
"\n",
|
||||
"spaghetti\n",
|
||||
"\n",
|
||||
"rice\n",
|
||||
"\n",
|
||||
"cake\n",
|
||||
"\n",
|
||||
"broccoli\n",
|
||||
"\n",
|
||||
"cereal\n",
|
||||
"\n",
|
||||
"salad\n",
|
||||
"\n",
|
||||
"avocados\n",
|
||||
"\n",
|
||||
"ice cream\n",
|
||||
"\n",
|
||||
"fish\n",
|
||||
"\n",
|
||||
"strawberries\n",
|
||||
"\n",
|
||||
"bananas\n",
|
||||
"\n",
|
||||
"watermelon\n",
|
||||
"\n",
|
||||
"Which of the foods above is your favorite? burgers\n",
|
||||
"\n",
|
||||
"10 of your friends like burgers as well!\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"To get the status from the master branch, use the command below:\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"git status\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"**Output:**\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"On branch master\n",
|
||||
"\n",
|
||||
"nothing to commit, working tree clean\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"To track the git commit logs, use the following command:\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"git log\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"**Output:**\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"commit 57c54e10c808118898bb0f15625bda2c0f55fec3 (HEAD -> master, improve\\-output)\n",
|
||||
"\n",
|
||||
"Author: Name <user@example.com>\n",
|
||||
"\n",
|
||||
"Date: Tue Oct 31 08:57:01 2023 +0000\n",
|
||||
"\n",
|
||||
" Revert \"Rename item variable to food\\_item.\"\n",
|
||||
"\n",
|
||||
" This reverts commit 21cf376832fa6eace35c0bf9e4bae4a3400452e9.\n",
|
||||
"\n",
|
||||
"commit 80b47ced952bffe110e2f9f00769cd43ed047ac1\n",
|
||||
"\n",
|
||||
"Author: Name <user@example.com>\n",
|
||||
"\n",
|
||||
"Date: Tue Oct 31 08:55:24 2023 +0000\n",
|
||||
"\n",
|
||||
" Adding a line in the output describing the utility of food\\_count.py script\n",
|
||||
"\n",
|
||||
"commit 21cf376832fa6eace35c0bf9e4bae4a3400452e9\n",
|
||||
"\n",
|
||||
"Author: Alex Cooper <alex\\_cooper@gmail.com>\n",
|
||||
"\n",
|
||||
"Date: Wed Jan 8 14:09:39 2020 +0530\n",
|
||||
"\n",
|
||||
" Rename item variable to food\\_item.\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"## **Congratulations!**\n",
|
||||
"\n",
|
||||
"In this lab, you successfully created a branch from the master branch to add a new feature. You also rolled back a commit to where the script worked fine, and then merged it to the master branch. This will help as you work with colleagues who are simultaneously on the same repository."
|
||||
]
|
||||
}
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user