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.
What happens when we merge two branches?
Both branches are pointed at the same commit.
What is the purpose of organizing repositories into branches?
To enable changes to be worked on without disrupting the most current working state.
How do I know in which branch am I currently?
Use git branch
and look for the branch preceded by an asterisk *
Currently in the master branch in this example
Is is possible to delete a branch?
git branch -d <branch_name>
In case there are changes not commited, Git will ask us to confirm if we still want to delete it.
To overwrite this step, use git branch -D <branch_name>
instead.
What’s the advantage of Git throwing a merge conflict error in cases of overlap?
It prevents loss of work if two lines overlap.
When we merge two branches, one of two algorithms is used. If the branches have diverged, which algorithm is used?
Three-way merge
What command would we use to throw away a merge, and start over?
git merge --abort
What is the purpose of a Git repository, and how does it facilitate version control?
A Git repository is a version control system that tracks changes to source code, allowing multiple developers to collaborate, review changes, and maintain a complete history of project revisions.
In a Git repository, what command would you use to create a new branch based on the current branch, and what command would you use to switch to that newly created branch?
To create a new branch, use git branch new-branch-name
, and to switch to it, use git checkout new-branch-name
What is the primary purpose of merging a branch back into the main branch in a Git repository?
To combine the changes from the branch into the main codebase