Module 2 Flashcards
What does HEAD represent in Git?
The currently checked-out snapshot of your project
What is the purpose of the git checkout
command?
It reverts changes to modified files before they are staged.
It will revert to state from HEAD.
What is the gitignore file
What is the purpose of the git checkout -p
command?
It allows reverting specific changes only. Git will go through change by change and ask if I want to revert.
What is the purpose of the git reset
command?
It reverts changes to modified files after they’ve been staged.
It will revert to state from HEAD.
output.txt was incorrectly stagged by the git add *
command
How to use the git reset
command?
git reset HEAD <file name>
How to use the git checkout
command?
git checkout <file name>
What does the git commit --amend
do?
Overwrite the previous commit.
When git commit --amend
should not be used? Why so?
Avoid using it when commit has been pushed to a public/shared repository. It is acceptable only for local repositories.
The reason is that git commit --ammend
will overwrite previous commit and can lead to confusing situations when collaborating with others on the same code.
What does the git revert
do?
It creates a new commit with inverse changes.
Git does not delete the problematic commit as this would mean we would lose track of project history.
How to use git revert
?
It is good to add the reason for the rollback on the commit message.
How to revert to a commit other than the previous one?
Use the commit ID as argument instead of HEAD
~~~
git revert abb063210c1f011b0d6470a4c5f1d8f672edd3ef
~~~
How does Git ensure the commit ID is unique to each commit?
It uses the SHA1 algorithm to create a hash that takes into consideration the commit message, date, author, and the snapshot taken of the working tree.
Therefore, the chances that two different commits have the same hash is virtually impossible and if it does happen, it is an indicator that something went wrong (e.g. tampering with the repository)
What does the git checkout -b
new branch command do?
Creates a new branch and switches to it.
How does git checkout
switch branches?
By updating the working tree to match the selected branch.