Module 1: Introduction to Version Control

Spread the love

INTRODUCTION – Version Control

By the end of the module, you will learn how your code control consequences could be crucial. You will be able to differentiate both files and the available tools. Learn about Git and how it boosts your coding abilities. Once you understand Git, you can then install it and immediately start using it to create and clone code repositories. And, delve deeper into Git and get to know better about its various tools and commands.

Learning Objectives:

  • What is version control and why is it important?
  • Automation of differentiating and editing files using the diff and patch commands
  • Give an overview of Git and its benefits and anything else you want to know.
  • Install Git on your local machine.
  • Using Git, you can create and clone repositories, and also:
  • You can add code, check code status, and commit changes.

PRACTICE QUIZ: BEFORE VERSION CONTROL

1. Your colleague sent you a patch called fix_names.patch, which fixes a config file called fix_names.conf. What command do you need to run to apply the patch to the config file?

  • diff names.conf fix_names.conf
  • patch fix_names.conf names.conf
  • patch fix_names.conf < fix_names.patch (CORRECT)
  • diff names.conf_orig names.conf_fixed > fix_names.conf

Good stuff! It’s easy to use the ‘patch’ command, with the file to be patched first, followed by the patch file name, to execute the patch.

2. You’re helping a friend with a bug in a script called fix_permissions.py, which fixes the permissions of a bunch of files. To work on the file, you make a copy and call it fix_permissions_modified.py. What command do you need to run after solving the bug to send the patch to your friend?

  • diff fix_permissions.py fix_permissions_modified.py > fix_permissions.patch (CORRECT)
  • patch fix_permissions.py < fix_permissions_modified.py
  • patch fix_permissions.py > fix_permissions.patch
  • diff fix_permissions.py fix_permissions.diff

Awesome! Comparing differences among files or updating them is what the diff command is used for.

3. The _____ commandhighlights the words that changed in a file instead of working line by line.

  • diff
  • diff -u
  • wdiff (CORRECT)
  • patch

Right on! Aside from functioning line by line, the command wdiff -w “–” result-of-command-1 -x “–” result-of-command-2 -y “–” offers the services with the fact that the text changed in a file is highlighted by colors.

4. How can we choose the return value our script returns when it finishes?

  • Using the exit command from the sys module (CORRECT)
  • Use the patch command
  • Use the diff command 
  • Use meld

Great work! A way of ending processing when a script processes a particular number in the argument passed to the script is to use the following scheme: sys.exit() from the python script and use the argument number pier after this to return the script’s return code.

5. In addition to the original files, what else do we need before we can use the patch command?

  • Diff file (CORRECT)
  • exit command of the sys module
  • Version control
  • Full copy of the new files

Woohoo! In order to replace new changes in the original file, patch command with diff has to be used.

6. What’s the goal of a version control system?

  • To make sure that our code has no bugs
  • To keep track of changes made to our files (CORRECT)
  • To have backup copies of our code
  • To store code, images, configuration, and videos

Right on! By using a versioning system, it is very simple to track changes in filenames to know who did it and on which date. Different ‘changes’ could be in the form of updates in the firewall configuration, changes in the web server settings, or changes to the network and software codes.

7. What’s the goal of the diff tool?

  • To keep track of changes to our files
  • To check if our changes make sense
  • To highlight new lines in Python filesTo show the differences between two files (CORRECT)

You got it! Highlight and show the things changed, and let’s know what was altered and how they were done on documents by a comparison tool.

8. What does the patch command do?

  • It generates a file with the differences between two files.
  • It shows the changes made in a directory of files.
  • It redirects the contents of a file into standard input.
  • It applies the changes contained in a diff file to another file. (CORRECT)

Right on! Patch is the appropriate command by which these changes can be applied to actual files while diff is only what causes the differences in the files.

9. We’ve prepared a diff file with the changes that need to be applied to the script. What does our colleague need to do now?

  • Look at the changes in the diff file and manually modify the original file with those same changes.
  • Run diff disk_usage.diff disk_usage.py.
  • Ask us to send them the full file, not just the diff file.
  • Run patch disk_usage.py < disk_usage.diff. (CORRECT)

You nailed it! For any file we wish to alter, we would have to run the diff file through the patch command.

PRACTICE QUIZ: VERSION CONTROL SYSTEMS

1. How can a VCS (Version Control System) come in handy when updating your software, even if you’re a solo programmer? Check all that apply.

  • Git retains local copies of repositories, resulting in fast operations. (CORRECT)
  • If something breaks due to a change, you can fix the problem by reverting to a working version before the change. (CORRECT)
  • Git relies on a centralized server.
  • Git allows you to review the history of your project. (CORRECT)

Great! Everybody contributing to a repository will have a full repository stored locally.

Well done! This will help us to know exactly what caused the problem. Version control is a great way to just fix things, and we may investigate the details later on.

Right on! 

2. Who is the original creator and main developer of the VCS (Version Control System) tool Git?

  • Bill Gates
  • Guido van Rossum
  • Linus Torvalds (CORRECT)
  • James Gosling

Nailed it! A version control system for tracking changes in the source code during the software development process is the definition of Git by Linus Torvalds, who founded it in the year 2005 with the purpose of improving collaboration between the developers of the Linux kernel from around the world.

3. _____ is a feature of a software management system that records changes to a file or set of files over time so that you can recall specific versions later.

  • A repository
  • sys.exit()
  • Version control (CORRECT)
  • IDE

Right on! An older version keeps a record of the modifications in the pages that I have recently made.

4. A _____ is a collection of edits which has been submitted to the version control system for safe keeping.

  • IDE
  • version control system
  • commit (CORRECT)
  • repository

Awesome! We call the collection of edits we are making at one time a commit.

5. Within a VCS, project files are organized in centralized locations called _____ where they can be called upon later.

  • commits
  • repositories (CORRECT)
  • IDE
  • yum

Excellent. A repository is a central location in which data is stored and managed.

6. What does a version control system do?

  • It groups all related code.
  • It explains why a change was made.
  • It keeps track of changes we do to our files. (CORRECT)
  • It prevents us from changing files by mistake.

Correct!Exactly! So, if you work on a file with others, you will naturally have updates happening almost every other day for the file; there will come a time, maybe inside of five years, when none of the original and the final versions of the file will be the same.

7. Why is a version control system useful, even if it’s used only by a single person? Check all that apply.

  • Seeing the history of the changes helps us understand what changed and why. (CORRECT)
  • Tracking code in a VCS ensures that it’s bug free.
  • Tracking changes allows for easy rollbacks when a problem is detected. (CORRECT)
  • Storing files in a VCS avoids the need for any kind of backups.

In fact, how the file got altered over the course of history could be understood. At each step, knowledge of what changed and what made the changes could be developed:

This information is tracked in the VCS such that every change can very conveniently be attached to previous versions.

8. What characteristics make Git particularly powerful? Check all that apply.

  • It was created by Linus Torvalds in 2005.
  • It’s a distributed VCS, which means that each developer has a full copy of the repository. (CORRECT)
  • It’s maintained by a team of distributed developers.Repositories can be used by as many developers as needed. (CORRECT)

Correct! Git repositories contain multiple contributors’ full records; therefore, multiple tracked files interact without needing a coordinating server. This allows better cooperation between developers.

Right on! Because of the design choices Git made, repositories may be large or small, developed by tens or even hundreds of millions of developers.

9. What’s the command that you need to run to check what version of Git is currently installed in your computer?

  • git init
  • git show version
  • git commit
  • git –version (CORRECT)

You got it! Running git –version in your computer will display the currently installed version of Git (if Git is installed on your computer).

PRACTICE QUIZ: USING GIT

1. Before changes in new files can be added to the Git directory, what command will tell Git to track our file in the list of changes to be committed?

  • git status
  • git add (CORRECT)
  • git commit 
  • git init

Right on! git add will add a file to the staging area and mark it for tracking.

2. Which command would we use to review the commit history for our project?

  • git clone
  • git status (CORRECT)
  • git config -l
  • git log

Awesome! The git log is a tool for gathering event logs generated by the git software.

3. What command would we use to make Git track our file?

  • git clone
  • git status
  • git add (CORRECT)
  • git log

Great work!git add is used to mark a file as tracked by Git.

4. Which command would we use to look at our config?

  • git clone
  • git status
  • git config -l (CORRECT)
  • git log

Great work! git config -l is used to check the current user configuration.

5. Which command would we use to view pending changes?

  • git clone
  • git status (CORRECT)
  • git config -l
  • git log

Woohoo! git status is used to retrieve information about changes waiting to be committed.

6. What are the git directory and the working tree?

  • The git directory stores configuration settings and the working tree stores the history of the files.
  • The git directory is copied to the computer and the working tree stays in the remote repository.
  • The git directory is a sandbox for changing the files and the working tree contains old versions of the files.
  • The git directory contains all the changes and their history and the working tree contains the current versions of the files. (CORRECT)

Okay. The database Git keeps track of any changes made in Git, it’s a way of explaining what a working tree is for crunching out pairs of new versions of files at a time.

7. What do we need to do after modifying a file tracked by Git?

  • We need to stage the file, so that the changes will be included in the next commit. (CORRECT)
  • We need to commit the file, so that the changes will become part of the staging area.
  • We need to add the file to the Git directory.
  • We need to change to a different working tree.

You nailed it! Please use git add to stage the changes after you modify a file. Else commit the changes with git commit.

8. When committing new files or changes with git commit, the user is asked to provide a commit message. What will happen if an empty commit message is entered?

  • It will make it difficult to track bugs without commit messages.
  • The info shown with the git log command will show no commit message.
  • The commit will be aborted. (CORRECT)
  • The commit will ignore untracked files or files that weren’t staged.

Nice work! You can’t commit with an empty commit message.

9. What should your commit message look like?

  • A jumble of words
  • A description of no more than 50 characters
  • A short description of the change (up to 50 characters), followed by one or more paragraphs giving more details of the change (if needed). (CORRECT)
  • Always write as much as you can about the changes.

Awesome! You want your message to contain all relevant information without being confusing.

INTRODUCTION TO GIT

1. What do you need to do before you install Git on your Linux VM? 

  • Make sure that you have a fresh index of the packages available to you. (CORRECT)
  • Check which version of Git will be installed.
  • Initialize a repository.
  • Create a directory.

Correct

2. What does the command git –version do? 

  • Installs Git
  • Updates Git to the latest version
  • Uninstalls Git
  • Checks if Git is installed and shows the version (CORRECT)

Correct

3. When viewing the status of files of the project, where are the files listed that Git is not yet tracking? 

  • They are not listed in the status.
  • Under “Untracked files” (CORRECT)
  • Under “Uncommitted files”
  • Under “Working files”

Correct

4. What is the command for moving files to the staging area? 

  • git commit
  • git add (CORRECT)
  • git move
  • git config

Correct

5. What command would you use to add the commit message “Revisions complete” at the same time you enter a git commit command?

  • git commit -m [Revisions complete]
  • git commit “Revisions complete”
  • git commit -m “Revisions complete” (CORRECT)
  • git commit -cm “Revisions complete”

Correct

6. What command will allow you to view all the commits?

  • git log (CORRECT)
  • git updates
  • git commit -s
  • git status

Correct

7. Which of the following best describes Git? 

  • A version control system (CORRECT)
  • A repository
  • A VM instance
  • A database

Correct

8. What is the first step to create a new repository in Git? 

  • Clone an existing repository using git clone
  • Initialize a new repository using git init (CORRECT)
  • Fork a repository from GitHub using git fork
  • Create a new branch in a repository using git create

Correct

9. The git config command has several functions. Which of the following is one of them?

  • To creates a .git subdirectory in the current working directory
  • To change the user email associated with future Git commits (CORRECT)
  • To change the user email associated with previous Git commits
  • To create a HEAD file which points to the currently checked out commit.

Correct

10. What is the best description of a repository from the choices below? 

  • A repository is a location where all the files of a particular project are stored. (CORRECT)
  • A repository is all changes whether they have been staged or not. 
  • A repository is a collection of Virtual Machines.

Correct

11. What is the first step to install Git on a Linux machine? 

  • Run sudo apt install git in the terminal (CORRECT)
  • Create a GitHub account
  • Run git –version in the terminal
  • Download Git from the official website

Correct

12. What is the best definition below of the staging area? 

  • A directory without a GIt repository
  • Where files are not yet tracked by Git
  • A repository of Git commits
  • Where files are gathered and prepared for Git before committing them (CORRECT)

Correct

13. After you have made a commit, what command can you use to look at the changes?

  • git status
  • git add
  • git diff (CORRECT)
  • git changes

Correct

14. What is the purpose of the git config command? 

  • To create a new branch in the repository
  • To display the current status of the repository
  • To stage changes for the next commit
  • To configure global or repository-specific settings (CORRECT)

Correct

15. What will the command nano README return?

  • A text file named README (CORRECT)
  • A repository named README
  • A status report named README
  • A directory named README

Correct

16. When using the -m flag to add the commit message at the same time you enter a git commit command, what happens if multiple -m flags are given to the command?

  • The first commit message is saved.
  • The commit message values are concatenated as separate paragraphs. (CORRECT)
  • The last commit message is saved.
  • The commit message values are combined into a single paragraph.

Correct

17. The git init command has several functions. Which of the following is one of them?

  • To convert an existing, unversioned project to a Git repository (CORRECT)
  • To override an existing .git configuration.
  • To configure Git
  • To create a new directory

Correct

18. When viewing the status of files of the project, where are the files listed have been moved to the staging area using the git add command? 

  • Under “Changes to be tracked”
  • Under “Changes to be saved”
  • They are not listed in the status.
  • Under “Changes to be committed” (CORRECT)

Correct

19. What is the result of using the git commit command? Select all that apply. 

  • It changes the configuration of the repository.
  • It changes the status of the repository.
  • A snapshot is captured of the project’s currently staged changes. (CORRECT)
  • It stores the current contents of the index in a new commit along with the commit message. (CORRECT)

Correct

20. What will the git log command display (if you have not used any options to limit the output of this command)?

  • The status of the repository
  • A unique commit ID at the top of each commit (CORRECT)
  • The commit history of the repository (CORRECT)
  • The commit message (CORRECT)

Correct

21. What is Git primarily used for? 

  • Creating websites
  • Designing graphics
  • Managing databases
  • Version control (CORRECT)

Correct

22. What command will display changes that have been staged, changes that haven’t been staged, and files that aren’t tracked by Git.? 

  • git status (CORRECT)
  • git config
  • git init
  • git commit

Correct

23. After you enter a commit message, how do you save that message?

  • Press Ctrl-o and Enter key. (CORRECT)
  • Use the git message command.
  • Use the git commit command.
  • Use the git add command.

Correct

24. Using the git diff command will let you see changes made to the file. How can you spot these changes?

  • Lines with new additions start with “add”, lines with replacements/removals start with “subtract”.
  • Lines with new additions end with a plus (+) sign, lines with replacements/removals end with a minus (-) sign.
  • Lines with new additions have the latest version number, lines with replacements/removals shave earlier version numbers. 
  • Lines with new additions start with a plus (+) sign, lines with replacements/removals start with a minus (-) sign. (CORRECT)

Correct

CONCLUSION – Introduction to Version Control

Thus, regarding all this as jeopardy by overloaded response, this module comprises installing and implementing a deep-insight-in version control, recognizing many things about managing codes and rollback even on the series of hands-on concepts learned. Code organization becomes effective before those two senses, which is separating the files from other worthwhile tasks.

Thus, any explanation of a further concept, like Git, may already make the relevance of being able to use the capabilities leaning towards strong-platform version control systems. It is a fundamental introduction to Git which means the entire module concludes your learning with formation of its repositories with cloning and code creating properties; understand what kind of tools Git actually provides and what commands. With these skills, you also learn arguments in good code blueprinting for version control and theoretically reach new levels.

Leave a Comment