Git: the basic commands
The everyday local commands, status, add, commit, diff, restore and log: what each one reads or changes in the working directory, the index and the repository.
- 22 cards
- 5 topics
- Free
The outline, topic by topic
Each topic is weighted the way the exam weighs it.
- Concepts
- Questions
- Sort and link
- Scenarios
- Understand
A few cards from the deck
git status: what is it?
Show the answer
Shows the current branch and the state of the files: staged, modified but not staged, untracked.
It changes nothing. It is the reflex before any commit: it tells what will go, what will not, and the command to change that.
You have just run
git add a.txtwith no other change. What doesgit diffshow?- Nothing: the working directory and the index are identical
- The changes that git add has just staged
- The changes to a.txt since the last commit
- An error: a file or a commit must be given
Show the answer
Nothing: the working directory and the index are identical
git diffcompares the working directory with the index. Once the file is added, they are the same. To see what was just staged, usegit diff --staged.git … turns the current folder into a repository by creating the .git folder.
Show the answer
git init turns the current folder into a repository by creating the .git folder.
No project file is touched. The files already there stay untracked until the first git add.
git add: what is it?
Show the answer
Copies the current state of a file into the index; if the file was new, it becomes tracked.
The state copied is that of the moment: a change made afterwards needs another add to go into the commit.
config.txt was staged by mistake, but you want to keep its changes in the file. What do you do?
git restore config.txtgit rm config.txtgit reset --hardgit restore --staged config.txt
Show the answer
git restore --staged config.txtOnly the first one takes the file out of the index while keeping its content.
git restore config.txtcopies the index back into the file: the file stays staged.git rmrefuses here (“changes staged in the index”) and would aim to delete the file anyway.git reset --hardoverwrites all uncommitted work.