Skip to the task
Layout
Back to classic view

You are looking ahead. Your place is still task 1: Style.

READTask 14 of 23 · step 7: Git: history and changesGit: history and changes
Git: history and changes in practice/01/

The Log window (Alt+9), reviewing before a commit (Ctrl+K), Rollback and Revert, a good commit message, and push.

Details & hint

Since topic 1 you have finished every task with a commit. Each commit is a snapshot of the project with a message. This topic already has several, so it is time to use the history.

The history

Alt+9 opens the Git window, the Log tab. On the left is the list of commits, newest at the top. Click Reformat code: on the right you see which files changed. Double-click main.c and a diff opens: what it was on the left, what it became on the right.

Compare it with Start counter at 0: one line changed there. That is why it pays to do one task in one commit: a month later you see straight away where the bug was fixed.

Before a commit

Ctrl+K shows all the changed files. Double-click a file and look through exactly what you are about to save. There must be no build/ or .exe in it: .gitignore keeps them out.

Undoing

  • Not committed yet: right-click the file in the Commit window → Rollback. The file goes back to how it was in the last commit.
  • Already committed: right-click the commit in the Log window → Revert Commit. A new commit is made that undoes that change, and the history stays.
  • Who changed a line, and when: right-click the gutter → Annotate with Git Blame.

A good commit message

The message says what the commit does and, if it isn't obvious, why. In this course it is short, in English and in the imperative, as if finishing "This commit will ...": Add grade input, not Added grade input. About 50 characters at most.

Good Bad
Start counter at 0 fix
Check input in a while loop changes
HW 2: Round with (int)(x + 0.5) asdf

Push

Commits are kept on your computer. Push sends them to GitHub: Ctrl+Shift+K. Only then does GitHub run the tests and the lecturer see your work.

The same in the terminal

Git commands work in CLion's terminal (Alt+F12) too:

Command What it does
git status what changed but isn't committed yet
git log --oneline the history, one line each
git diff exactly what you changed
practice 01 main.c Code Diff
UNCHANGED This step does not change this file.
#include <stdio.h>
int main(void) {
printf("Hello, world!\n");
printf("\n");
printf("Algorithm: the average of grades\n");
printf("1. Add up all the grades.\n");
printf("2. Count how many grades there are.\n");
printf("3. Divide the sum by the count.\n");
printf("4. Print the answer.\n");
printf("\n");
printf("Grade\tMeaning\n");
printf("10\t\"excellent\"\n");
printf("5\t\"satisfactory\"\n");
printf("File: C:\\course\\practice\\01\\main.c\n");
printf("Done: 100%%\n");
return 0;
}