{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Skipping the Staging Area\n", "\n", "This reading contains the code used in the instructional videos from [**Skipping the Staging Area**Opens in a new tab](https://www.coursera.org/learn/introduction-git-github/lecture/uAFPm/skipping-the-staging-area).\n", "\n", "## Introduction\n", "\n", "This follow-along reading is organized to match the content in the video that follows. It contains the same code shown in the next video. These code blocks will provide you with the opportunity to see how the code is written and can be used as a reference as you work through the course. \n", "\n", "You can follow along in the reading as the instructor discusses the code or review the code after watching the video.\n", "\n", "```bash\n", "cd scripts\n", "\n", "atom all\\_checks.py\n", "```\n", "\n", "## File with code\n", "\n", "```bash\n", "#!/usr/bin/env python3\n", "\n", "import os\n", "\n", "import sys\n", "\n", "def check\\_reboot():\n", "\n", "    \"\"\"Returns True if the computer has a pending reboot.\"\"\"\n", "\n", "    return os.path.exists(\"/run/reboot-required\")\n", "\n", "def main():\n", "\n", "    if check\\_reboot():\n", "\n", "        print(\"Pending Reboot.\")\n", "\n", "        sys.exit(1)\n", "\n", "main()\n", "```\n", "\n", "```bash\n", "git commit \\-a \\-m \"Call check\\_reboot from main, exit with 1 on error\"\n", "```\n", "\n", "**Code output:**\n", "\n", "\\[master 033f27a\\] Call check\\_reboot from main, exit with 1 on error\n", "\n", " 1 file changed, 4 insertions(+), 1 deletion(-)\n", "\n", "```bash\n", "git log\n", "```\n", "\n", "**Code output:**\n", "\n", "commit 033f27a8196987d61c4fd42930f2148b23434a03 (HEAD -> master)\n", "\n", "Author: My name \n", "\n", "Date:   Mon Jul 15 14:39:18 2019 +0200\n", "\n", "    Call check\\_reboot from main, exit with 1 on error\n", "\n", "commit cc1acbf10fdea6cc07ebf827697666b6a35b0f36\n", "\n", "Author: My name \n", "\n", "Date:   Thu Jul 11 17:19:32 2019 +0200\n", "\n", "    Add a check\\_reboot function\n", "\n", "commit 6cfc29966acda8213fcd8ac2735b31f3fdbc6c53\n", "\n", "Author: My name \n", "\n", "Date:   Thu Jul 11 12:08:46 2019 +0200\n", "\n", "    Create and empty all\\_checks.py" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Getting more information from the user\n", "\n", "This reading contains the code used in the instructional videos from [**Getting More Information About Our Changes**Opens in a new tab](https://www.coursera.org/learn/introduction-git-github/lecture/KLQkB/getting-more-information-about-our-changes)\n", "\n", "## Introduction\n", "\n", "This follow-along reading is organized to match the content in the video that follows. It contains the same code shown in the next video. These code blocks will provide you with the opportunity to see how the code is written and can be used as a reference as you work through the course. \n", "\n", "You can follow along in the reading as the instructor discusses the code or review the code after watching the video.\n", "\n", "```bash\n", "git log \\-p\n", "```\n", "\n", "**Code output:**\n", "\n", "commit 033f27a8196987d61c4fd42930f2148b23434a03 (HEAD -> master)\n", "\n", "Author: My name \n", "\n", "Date:   Mon Jul 15 14:39:18 2019 +0200\n", "\n", "    Call check\\_reboot from main, exit with 1 on error\n", "\n", "diff --git a/all\\_checks.py b/all\\_checks.py\n", "\n", "index 340f1f7..710266a 100644\n", "\n", "\\--- a/all\\_checks.py\n", "\n", "+++ b/all\\_checks.py\n", "\n", "@@ -1,12 +1,15 @@\n", "\n", " #!/usr/bin/env python3\n", "\n", " import os\n", "\n", "+import sys\n", "\n", " def check\\_reboot():\n", "\n", "     \"\"\"Returns True if the computer has a pending reboot.\"\"\"\n", "\n", "     return os.path.exists(\"/run/reboot-required\")\n", "\n", "(...)\n", "\n", "```bash\n", "git log\n", "```\n", "\n", "**Code output:**\n", "\n", "commit 033f27a8196987d61c4fd42930f2148b23434a03 (HEAD -> master)\n", "\n", "Author: My name \n", "\n", "Date:   Mon Jul 15 14:39:18 2019 +0200\n", "\n", "    Call check\\_reboot from main, exit with 1 on error\n", "\n", "commit **cc1acbf10fdea6cc07ebf827697666b6a35b0f36**\n", "\n", "Author: My name \n", "\n", "Date:   Thu Jul 11 17:19:32 2019 +0200\n", "\n", "    Add a check\\_reboot function\n", "\n", "(...)\n", "\n", "user@ubuntu:~/scripts$ git show cc1acbf10fdea6cc07ebf827697666b6a35b0f36\n", "\n", "commit cc1acbf10fdea6cc07ebf827697666b6a35b0f36\n", "\n", "Author: My name \n", "\n", "Date:   Thu Jul 11 17:19:32 2019 +0200\n", "\n", "    Add a check\\_reboot function\n", "\n", "diff --git a/all\\_checks.py b/all\\_checks.py\n", "\n", "index c0d03b3..340f1f7 100644\n", "\n", "\\--- a/all\\_checks.py\n", "\n", "+++ b/all\\_checks.py\n", "\n", "@@ -1,5 +1,11 @@\n", "\n", " #!/usr/bin/env python3\n", "\n", "+import os\n", "\n", "+\n", "\n", "+def check\\_reboot():\n", "\n", "+    \"\"\"Returns True if the computer has a pending reboot.\"\"\"\n", "\n", "+    return os.path.exists(\"/run/reboot-required\")\n", "\n", "+\n", "\n", " def main():\n", "\n", "     Pass\n", "\n", "```bash\n", "git log \\--stat\n", "```\n", "\n", "**Code output:**\n", "\n", "commit 033f27a8196987d61c4fd42930f2148b23434a03 (HEAD -> master)\n", "\n", "Author: My name \n", "\n", "Date:   Mon Jul 15 14:39:18 2019 +0200\n", "\n", "    Call check\\_reboot from main, exit with 1 on error\n", "\n", " all\\_checks.py | 5 ++++-\n", "\n", " 1 file changed, 4 insertions(+), 1 deletion(-)\n", "\n", "(...)\n", "\n", "```bash\n", "atom  all\\_checks.py\n", "```\n", "\n", "## File in video\n", "\n", "```bash\n", "#!/usr/bin/env python3\n", "\n", "import os\n", "\n", "import sys\n", "\n", "def check\\_reboot():\n", "\n", "    \"\"\"Returns True if the computer has a pending reboot.\"\"\"\n", "\n", "    return os.path.exists(\"/run/reboot-required\")\n", "\n", "def main():\n", "\n", "    if check\\_reboot():\n", "\n", "        print(\"Pending Reboot.\")\n", "\n", "        sys.exit(1)\n", "\n", "    print(\"Everything ok.\")\n", "\n", "    sys.exit(0)\n", "\n", "main()\n", "```\n", "\n", "```bash\n", "git diff\n", "```\n", "\n", "**Code output:**\n", "\n", "diff --git a/all\\_checks.py b/all\\_checks.py\n", "\n", "index 710266a..fdc4476 100644\n", "\n", "\\--- a/all\\_checks.py\n", "\n", "+++ b/all\\_checks.py\n", "\n", "@@ -12,4 +12,7 @@ def main():\n", "\n", "         print(\"Pending Reboot.\")\n", "\n", "         sys.exit(1)\n", "\n", "+    print(\"Everything ok.\")\n", "\n", "+    sys.exit(0)\n", "\n", "+\n", "\n", " main()\n", "\n", "```bash\n", "git  add \\-p\n", "```\n", "\n", "**Code output:**\n", "\n", "diff --git a/all\\_checks.py b/all\\_checks.py\n", "\n", "index 710266a..fdc4476 100644\n", "\n", "\\--- a/all\\_checks.py\n", "\n", "+++ b/all\\_checks.py\n", "\n", "@@ -12,4 +12,7 @@ def main():\n", "\n", "         print(\"Pending Reboot.\")\n", "\n", "         sys.exit(1)\n", "\n", "+    print(\"Everything ok.\")\n", "\n", "+    sys.exit(0)\n", "\n", "+\n", "\n", " main()\n", "\n", "Stage this hunk \\[y,n,q,a,d,e,?\\]? y\n", "\n", "user@ubuntu:~/scripts$ \n", "\n", "```bash\n", "git diff\n", "\n", "git diff \\--staged\n", "```\n", "\n", "**Code output:**\n", "\n", "diff --git a/all\\_checks.py b/all\\_checks.py\n", "\n", "index 710266a..fdc4476 100644\n", "\n", "\\--- a/all\\_checks.py\n", "\n", "+++ b/all\\_checks.py\n", "\n", "@@ -12,4 +12,7 @@ def main():\n", "\n", "         print(\"Pending Reboot.\")\n", "\n", "         sys.exit(1)\n", "\n", "+    print(\"Everything ok.\")\n", "\n", "+    sys.exit(0)\n", "\n", "+\n", "\n", " main()\n", "\n", "```bash\n", "git commit \\-m 'Add a message when everything is ok'\n", "```\n", "\n", "**Code output:**\n", "\n", "\\[master 49d610b\\] Add a message when everything is ok\n", "\n", " 1 file changed, 3 insertions(+)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Deleting and Renaming Files\n", "\n", "This reading contains the code used in the instructional videos from [**Deleting and Renaming FIles**Opens in a new tab](https://www.coursera.org/learn/introduction-git-github/lecture/3OT51/deleting-and-renaming-files)\n", "\n", "## Introduction\n", "\n", "This follow-along reading is organized to match the content in the video that follows. It contains the same code shown in the next video. These code blocks will provide you with the opportunity to see how the code is written and can be used as a reference as you work through the course. \n", "\n", "You can follow along in the reading as the instructor discusses the code or review the code after watching the video.\n", "\n", "```bash\n", "cd checks/\n", "\n", "ls \\-l\n", "```\n", "\n", "**Code output:**\n", "\n", "total 8\n", "\n", "\\-rw-rw-r-- 1 user user 659 Jul  9 19:28 disk\\_usage.py\n", "\n", "\\-rw-rw-r-- 1 user user 659 Jul 15 21:43 processes.py\n", "\n", "```bash\n", "git rm process.py\n", "```\n", "\n", "**Code output:**\n", "\n", "rm '[processes.pyOpens in a new tab](http://processes.py/)'\n", "\n", "```bash\n", "ls \\-l \n", "```\n", "\n", "**Code output:**\n", "\n", "total 4\n", "\n", "\\-rw-rw-r-- 1 user user 659 Jul  9 19:28 disk\\_usage.py\n", "\n", "```bash\n", "git status\n", "```\n", "\n", "**Code output:**\n", "\n", "On branch master\n", "\n", "Changes to be committed:\n", "\n", "  (use \"git reset HEAD ...\" to unstage)\n", "\n", "        deleted:    [processes.pyOpens in a new tab](http://processes.py/)\n", "\n", "```bash\n", "git commit \\-m 'Delete unneeded processes file'\n", "```\n", "\n", "**Code output:**\n", "\n", "\\[master 9939311\\] Delete unneeded processes file\n", "\n", " 1 file changed, 24 deletions(-)\n", "\n", " delete mode 100644 processes.py\n", "\n", "```bash\n", "git mv disk\\_usage.py check\\_free\\_space.py\n", "\n", "git status\n", "```\n", "\n", "**Code output:**\n", "\n", "On branch master\n", "\n", "Changes to be committed:\n", "\n", "  (use \"git reset HEAD ...\" to unstage)\n", "\n", "        renamed:    disk\\_usage.py -> check\\_free\\_space.py\n", "\n", "```bash\n", "git commit \\-m 'New name for disk\\_usage.py'\n", "```\n", "\n", "**Code output:**\n", "\n", "\\[master 7d7167b\\] New name for disk\\_usage.py\n", "\n", " 1 file changed, 0 insertions(+), 0 deletions(-)\n", "\n", "```bash\n", "echo .DS\\_STORE > gitignore\n", "\n", "ls \\-la\n", "```\n", "\n", "**Code output:**\n", "\n", "total 20\n", "\n", "drwxrwxr-x  3 user user 4096 Jul 15 22:15 .\n", "\n", "drwxr-xr-x 19 user user 4096 Jul 15 16:37 ..\n", "\n", "\\-rw-rw-r--  1 user user  659 Jul  9 19:28 check\\_free\\_space.py\n", "\n", "drwxrwxr-x  8 user user 4096 Jul 15 21:52 .git\n", "\n", "\\-rw-rw-r--  1 user user   10 Jul 15 22:15 .gitignore\n", "\n", "```bash\n", "git add .gitignore \n", "\n", "git commit \\-m 'Add a gitignore file, ignoring .DS\\_STORE files'\n", "```\n", "\n", "**Code output:**\n", "\n", "\\[master abb0632\\] Add a gitignore file, ignoring .DS\\_STORE files\n", "\n", " 1 file changed, 1 insertion(+)\n", "\n", " create mode 100644 .gitignore" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Study Guide: Advanced Git\n", "\n", "| Command | Explanation & Link |\n", "| --- | --- |\n", "| git commit -a | [$ git commit -aOpens in a new tab](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---all) automatically stages the files that have been locally modified. New files which have not been published yet are not affected. |\n", "| git log -p | [$ git log -pOpens in a new tab](https://git-scm.com/docs/git-log#generate_patch_text_with_p) produces patch text that displays the lines of code that were changed in each commit in the current repo. |\n", "| git show | [$ git showOpens in a new tab](https://git-scm.com/docs/git-show) shows you one or more object(s) such as blobs, trees, tags, and commits. |\n", "| git diff | [$ git diffOpens in a new tab](https://git-scm.com/docs/git-diff) is similar to the Linux \\`diff\\` command, and can show the changes between commits, changes between the working tree and index, changes between two trees, changes from a merge, and so on. |\n", "| git diff --staged | [$ git diff --stagedOpens in a new tab](https://git-scm.com/docs/git-diff) is an alias of $ git diff --cached, which  shows all staged files compared to the named commit. |\n", "| git add -p | [$ git add -pOpens in a new tab](https://git-scm.com/docs/git-add) allows a user to interactively review patches before adding to the current commit. |\n", "| git mv | [$ git mvOpens in a new tab](https://git-scm.com/docs/git-mv) is similar to the Linux \\`mv\\` command. This command can move or rename a file, directory, or symlink. |\n", "| git rm | [$ git rm Opens in a new tab](https://git-scm.com/docs/git-rm)is similar to the Linux \\`rm\\` command. This command deletes or removes a file from the working tree. |\n", "\n", "There are many useful git command summaries online as well. Please take some time to research and study a few, such as [this oneOpens in a new tab](https://education.github.com/git-cheat-sheet-education.pdf).\n", "\n", "## .gitignore files\n", "\n", ".gitignore files are used to tell the git tool to intentionally ignore some files in a given Git repository. For example, this can be useful for configuration files or metadata files that a user may not want to check into the master branch. \n", "\n", "When writing a .gitignore file, there are some specific formats which help tell Git how to read the text in the file. For example, a line starting with # is a comment; a slash / is a directory separator. Visit [https://git-scm.com/docs/gitignoreOpens in a new tab](https://git-scm.com/docs/gitignore) to see more examples.\n", "\n", "[This GitHub repositoryOpens in a new tab](https://gist.github.com/octocat/9257657) offers some examples of configurations which are often included in a .gitignore file. These examples include: compiled sources, packages, logs, databases, and OS generated files." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Undoing Changes Before Committing\n", "\n", "This reading contains the code used in the instructional videos from [**Undoing changes before committing**Opens in a new tab](https://www.coursera.org/learn/introduction-git-github/lecture/LPJn7/undoing-changes-before-committing)\n", "\n", "## Introduction\n", "\n", "This follow-along reading is organized to match the content in the video that follows. It contains the same code shown in the next video. These code blocks will provide you with the opportunity to see how the code is written and can be used as a reference as you work through the course. \n", "\n", "You can follow along in the reading as the instructor discusses the code or review the code after watching the video.\n", "\n", "```bash\n", "cd scripts\n", "\n", "atom all\\_checks.py\n", "```\n", "\n", "## File in video\n", "\n", "```bash\n", "#!/usr/bin/env python3\n", "\n", "import os\n", "\n", "import sys\n", "\n", "def main():\n", "\n", "    if check\\_reboot():\n", "\n", "        print(\"Pending Reboot.\")\n", "\n", "        sys.exit(1)\n", "\n", "    print(\"Everything ok.\")\n", "\n", "    sys.exit(0)\n", "\n", "main()\n", "```\n", "\n", "```bash\n", "./all\\_checks.py \n", "```\n", "\n", "**Code output:**\n", "\n", "Traceback (most recent call last):\n", "\n", "  File \"all\\_checks.py\", line 14, in \n", "\n", "    main()\n", "\n", "  File \"all\\_checks.py\", line 7, in main\n", "\n", "    if check\\_reboot():\n", "\n", "NameError: name 'check\\_reboot' is not defined\n", "\n", "```bash\n", "git status\n", "```\n", "\n", "**Code output:**\n", "\n", "On branch master\n", "\n", "Changes not staged for commit:\n", "\n", "  (use \"git add ...\" to update what will be committed)\n", "\n", "  (use \"git checkout -- ...\" to discard changes in working directory)\n", "\n", "        modified:   all\\_checks.py\n", "\n", "```bash\n", "git checkout all\\_checks.py\n", "\n", "git status\n", "```\n", "\n", "**Code output:**\n", "\n", "On branch master\n", "\n", "nothing to commit, working tree clean\n", "\n", "user@ubuntu:~/scripts$ ./all\\_checks.py \n", "\n", "Everything ok.\n", "\n", "```bash\n", "./all\\_checks.py \n", "```\n", "\n", "**Code output:**\n", "\n", "Everything ok.\n", "\n", "```bash\n", "./all\\_checks.py > output.txt\n", "\n", "git add \\*\n", "\n", "git status\n", "```\n", "\n", "**Code output:**\n", "\n", "On branch master\n", "\n", "Changes to be committed:\n", "\n", "  (use \"git reset HEAD ...\" to unstage)\n", "\n", "        new file:   output.txt\n", "\n", "```bash\n", "git reset HEAD output.txt\n", "\n", "git status\n", "```\n", "\n", "**Code output:**\n", "\n", "On branch master\n", "\n", "Untracked files:\n", "\n", "  (use \"git add ...\" to include in what will be committed)\n", "\n", "        Output.txt\n", "\n", "```bash\n", "git commit \\-m \"it should be os.path.exists\"\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# " ] }, { "cell_type": "markdown", "metadata": {}, "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python", "version": "3.13.2" } }, "nbformat": 4, "nbformat_minor": 2 }