Version control concepts (Git basics)

Computer Science · Software engineering

Question 1 of 10

0

    Which command shows the author and commit that last changed each line of a file?

    Stuck? Read the explanation

    Unlocks at a streak of 5 correct answers in a row.

    Print a free worksheet (PDF)

    Embed this practice on your site or class page

    Paste this HTML into your page. Students practise right there; it is free and needs no account.

    Version control concepts (Git basics) explained

    Version control records the history of a project so that changes can be tracked, compared and undone. Git is a widely used version control system that stores history as a series of commits inside a repository.

    A repository, or repo, is a project folder with a hidden history database. A commit is a saved snapshot of the files, with a message and a link to its parent commit. Because each commit points to its parent, the history forms a chain that can be walked backwards.

    Git prepares a commit in three areas. The working directory holds the files you edit. The staging area (the index) holds the changes you have selected for the next commit. The repository holds the committed history. You use git add to move changes into the staging area and git commit to save them.

    A branch is a movable pointer to a commit. Creating a branch lets you work on a feature without changing the main line of work. When the feature is ready, git merge combines its commits into the other branch. If the target branch has not moved, Git can fast-forward, which simply moves the branch pointer forward.

    Worked example

    The main branch has commits C1, C2 and C3. You create a branch called feature from C3 and add two commits, C4 and C5. Main still points to C3, while feature points to C5.

    1. The feature branch's history is C1, C2, C3, C4 and C5, which is 5 commits.
    2. Main still has 3 commits until the merge.
    3. If main has not moved, merging feature into main is a fast-forward, so main points to C5 and has 5 commits.

    Check: the number of commits added is 5−3=25 - 3 = 2, which matches the two commits made on the branch.

    What you will practise

    105 multiple-choice questions (Easy, Medium, Hard). Each answer is followed by an explanation.

    Example questions

    • Version control tracks:
    • A commit is:
    • Branches allow:
    • git merge:
    • git clone:
    • A repository is:
    • The command that stages changes for the next commit is:
    • The command that creates a new local repository in the current folder is:

    …and 97 more.