diff --git a/git/git-quiz.md b/git/git-quiz.md index 82b84ca2e1..77d77f75e9 100644 --- a/git/git-quiz.md +++ b/git/git-quiz.md @@ -9,6 +9,8 @@ [Reference](https://www.howtogeek.com/759319/how-to-check-and-update-your-git-version/) +[Reference](https://www.howtogeek.com/759319/how-to-check-and-update-your-git-version/) + #### Q2. What command lets you create a connection between a local and remote repository? - [ ] git remote add new @@ -35,6 +37,8 @@ git merge --squash HEAD@{1} - `git reset --hard HEAD~5` resets the current branch to the commit just before the last 5 (see `man gitrevisions` for details about this notation and other cool alternatives like `HEAD@{2 days ago}`). As it is a hard reset, it will also overwrite every change in the working tree as well. See `man git-reset`. - `git merge --squash HEAD@{1}` HEAD@{1} is where the branch was just before the previous command (again, see `man gitrevisions`). This command sets the state of the index to be as it would just after a merge from that commit. This whole operation could be a way to take 5 commits from a branch in which you started a new feature and squash them to a single commit, a meaningful one. +[Reference](https://stackoverflow.com/questions/70962338/documentation-of-default-target-of-git-merge-squash) + #### Q4. Your current project has several branches; master, beta, and push-notifications. You've just finished the notification feature in the push-notification branch, and you want to commit it to beta branch. How can you accomplish this? - [ ] Checkout the push-notifications branch and run git merge beta @@ -53,8 +57,8 @@ git merge --squash HEAD@{1} - [ ] All new files are staged - [ ] Only updated files are staged -[Reference](https://www.geeksforgeeks.org/difference-between-git-add-a-and-git-add/) - +- [Reference](https://git-scm.com/docs/git-add) +- [Reference](https://www.geeksforgeeks.org/difference-between-git-add-a-and-git-add/) #### Q6. What will the following command print to the Terminal? @@ -65,7 +69,8 @@ git merge --squash HEAD@{1} - [ ] An inline editor for modifying remote repositories - [ ] The last 5 git versions you've installed -[Reference](https://www.javatpoint.com/git-remote) +- [Reference](https://git-scm.com/docs/git-remote) +- [Reference](https://www.javatpoint.com/git-remote) #### Q7. Looking at the following commands, describe what is happening. @@ -80,6 +85,8 @@ git cherry-pick kj2342134sdf090093f0sdgasdf99sdfo992mmmf9921231 - [ ] A commit is being copied from the feature-user-location branch to the master branch - [ ] The branch is switched to the feature-user-location branch, and the specified commit is applied to the branch. +[Reference](https://git-scm.com/docs/git-cherry-pick) + Explanation: 'git checkout feature-user-location' switches to the 'feature-user-location' branch. @@ -95,7 +102,8 @@ So, this sequence of commands is cherry-picking a specific commit onto the featu - [ ] It keeps the HEAD at the current commit, but clears all previous commits. - [x] It sets HEAD to the previous commit and leaves changes from the undone commit in the stage/index. -[Reference](https://stackoverflow.com/questions/24568936/what-is-difference-between-git-reset-hard-head1-and-git-reset-soft-head) +- [Reference](https://git-scm.com/docs/git-reset) +- [Reference](https://stackoverflow.com/questions/24568936/what-is-difference-between-git-reset-hard-head1-and-git-reset-soft-head) #### Q9. You find a bug in your project, but can't locate where it was introduced in the commit history. How would you diagnose this problem? @@ -104,7 +112,8 @@ So, this sequence of commands is cherry-picking a specific commit onto the featu - [ ] Run a git rebase to find the buggy commit. - [x] Use git bisect to compare the buggy commit to an early commit that works as expected. -[Reference](https://stackoverflow.com/questions/69552866/how-to-diagnose-a-problem-in-git-commit-history) +- [Reference](https://git-scm.com/docs/git-bisect) +- [Reference](https://stackoverflow.com/questions/69552866/how-to-diagnose-a-problem-in-git-commit-history) #### Q10. Why would the following command be used? @@ -115,7 +124,8 @@ So, this sequence of commands is cherry-picking a specific commit onto the featu - [ ] To delete the last 10 commits and reset the HEAD - [ ] In order to locally cache the last 10 commits -[Reference](https://stackoverflow.com/questions/363908/how-do-i-use-git-rebase-i-to-rebase-all-changes-in-a-branch) +- [Reference](https://git-scm.com/docs/git-rebase#_interactive_mode) +- [Reference](https://stackoverflow.com/questions/363908/how-do-i-use-git-rebase-i-to-rebase-all-changes-in-a-branch) #### Q11. Why would you use a pre-receive hook in your remote repository? @@ -124,7 +134,8 @@ So, this sequence of commands is cherry-picking a specific commit onto the featu - [ ] To fire a script after updates are made to the remote repository - [ ] To debug all commit tags and release versions -[Reference](https://docs.github.com/en/enterprise-server@3.10/pull-requests/collaborating-with-pull-requests/collaborating-on-repositories-with-code-quality-features/working-with-pre-receive-hooks) +- [Reference](https://git-scm.com/docs/githooks) +- [Reference](https://docs.github.com/en/enterprise-server@3.10/pull-requests/collaborating-with-pull-requests/collaborating-on-repositories-with-code-quality-features/working-with-pre-receive-hooks) #### Q12. What option can you use to apply git configurations across your entire git environment? @@ -133,7 +144,8 @@ So, this sequence of commands is cherry-picking a specific commit onto the featu - [x] `--global` - [ ] `--update` -[Reference](https://www.git-scm.com/book/en/v2/Customizing-Git-Git-Configuration) +- [Reference](https://git-scm.com/docs/git-config) +- [Reference](https://www.git-scm.com/book/en/v2/Customizing-Git-Git-Configuration) #### Q13. How could you squash multiple commits together without using git merge --squash? @@ -142,7 +154,8 @@ So, this sequence of commands is cherry-picking a specific commit onto the featu - [x] Rebasing - [ ] Reflogging -[Reference](https://stackoverflow.com/questions/31409736/squash-commits-directly-on-feature-without-rebase-or-merge) +- [Reference](https://git-scm.com/docs/git-rebase#_interactive_mode) +- [Reference](https://stackoverflow.com/questions/31409736/squash-commits-directly-on-feature-without-rebase-or-merge) #### Q14. If you cloned an existing git repository, what would happen? @@ -151,7 +164,8 @@ So, this sequence of commands is cherry-picking a specific commit onto the featu - [ ] Nothing, cloning is not a supported git function - [ ] A copy of the repository would be created on the hosting platform -[Reference](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository) +- [Reference](https://git-scm.com/docs/git-clone) +- [Reference](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository) #### Q15. How can you display a list of files added or modified in a specific commit? @@ -160,7 +174,8 @@ So, this sequence of commands is cherry-picking a specific commit onto the featu - [ ] Run `git commit --info` with the commit hash. - [ ] Access the commit stash data with `git stash`. -[Reference](https://stackoverflow.com/questions/424071/how-do-i-list-all-the-files-in-a-commit#:~:text=If%20you%20want%20to%20get%20the%20list%20of,you%20can%20use%20git%20ls-tree%20--name-only%20-r%20%3Ccommit-ish%3E) +- [Reference](https://git-scm.com/docs/git-diff-tree) +- [Reference](https://stackoverflow.com/questions/424071/how-do-i-list-all-the-files-in-a-commit#:~:text=If%20you%20want%20to%20get%20the%20list%20of,you%20can%20use%20git%20ls-tree%20--name-only%20-r%20%3Ccommit-ish%3E) #### Q16. What files is this .gitignore programmed to leave out? @@ -177,6 +192,8 @@ build/ - [x] All files in the build directory, as well as files ending with .txt or .metadata - [ ] Only files with .swift and .txt extensions. +[Reference](https://git-scm.com/docs/gitignore) + A line starting with `#` serves as a comment. Hence `# .swift` does not do anything. See `man gitignore`. #### Q17. After you make changes to a local repository, you run the following command. What will this do? @@ -289,6 +306,8 @@ git bisect good 69faab6268350295550de7d587bc323d - [x] Squash the related commits together into a single coherent commit. - [ ] Stash the related commits under a new hash. +[Reference](https://git-scm.com/docs/git-rebase#_interactive_mode) + #### Q26. Which of the following is true of the git push command? **Note:** Which statement is true of the `git push` command? @@ -311,6 +330,8 @@ git push -u origin master - [ ] Same as before, git push -u origin master - [x] git push +[Reference](https://git-scm.com/docs/git-push) + #### Q28. How would you create a custom shortcut or command across your Git environment? - [ ] Run `git hotfix` with the shortcut name. @@ -318,6 +339,8 @@ git push -u origin master - [ ] Use the `git custom-key` command. - [x] Create an alias using the `git config` command. +[Reference](https://git-scm.com/docs/git-config) + #### Q29. What is the status of the beta-notes.js file in the following output? ```shell