-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Unnecessary Git Quiz
Nishant Joshi edited this page Feb 28, 2024
·
4 revisions
Here's a quick litmus test for anyone looking to contribute to Hyperswitch or any open source repository in general. This quiz encapsulates basic concepts that you'd need to get started. Haffun!
- In a recent commit someone created a new file, and moved functions from random files into this file (because modularity). Now it seems that there might be a bug in one of these functions, and the dev that created the file doesn't know the underline logic present in the functions, how can you quickly know who authored it?
[a]
git blame
[b]
git blame -C
[c]
git blame -C -C
[d]
git blame -C -C -C
Answer!
git blame -C -C # This is the right git blame -C -C -C # But, this isn't wrong! (why?)
- Which of the following commands are used to go to a different existing branch?
[a]
git branch <branch-name>
[b]
git switch <branch-name>
[c]
git branch -c <branch-name>
[d]
git checkout -b <branch-name>
Answer!
git switch <branch-name>
- You have made a few changes and added a few new files, turns out you have to start working on something else, so you need to keep everything that you have done aside, how will you do that?
Answer!
`git stash -u`
- You are reading a file in your local git repository, and you wish to know more about a certain function you saw in it, but there is no documentation, how can you get information about it?
Answer!
`git blame /path/to/file` and ask the author about more details
- What’s the difference between
git merge
andgit rebase
?
Answer!
git merge, ands a new commit to your new branch which gets the branch up-to-date with the branch that your are merging. git rebase on the other hand rebases the commits on top of the other branch. The following diagram explains it. U----V----W----X---- (your current branch) / / <--- (the merge) -A----B----C----D----F (branch to be merged)git merge U----V----W (branch after rebase) U----V----W / (branch before rebase) / / -A----B----C----D----F (branch to be merged)
git rebase
- Oops, someone accidentally pushed a commit to you main branch and that’s breaking quite a few things, what would you do, if you want to get the main branch stable again?
Answer!
`git revert HEAD`
- You have done some changes to your branch, you want to view those changes before committing them, what would you do to view what new code you have added.
[a]
git log
[b]
git show
[c]
git diff
[d]
git status
Answer!
`git diff`
- You are working on a new feature, while testing you found out that the application isn’t showing any logs. Luckily, a collaborator mentioned she added a commit just to enable logging in her own branch, but it was a long time back and she had added more commits after that, what would you do?
Answer!
`git cherrypick`
- You are getting ready for deploying your project on cloud, but the server configuration file in your branch is amiss, once again a collaborator to the rescue, lets you know that he has a proper config in one of his commit but unfortunately the commit also has other changes. you want to do a dry-run of the config by getting the changes from that single file into your current branch, which git command can accomplish this?
Answer!
`git checkout branc-name:/path/to/file`
- You have added a commit to your branch, the commit message looks something like,
feat(db): add new tabel to customre database
seems like it there are a few spelling mistakes, how can you fix the commit message?
Answer!
`git commit --amend`
- You are maintaining a rust project on GitHub, and someone raised a PR to it with the binaries for the compiled rust project, but those are huge and we don’t need them. What can you do, so that now one in the future is able to commit
/target
directory to the repo?
Answer!
Add the folder in `.gitignore`
- You had cloned your friends repository, and were working on it. You came up with a solid feature and committed it to your local branch, instead of sending the branch to his repository, you want to send it to your own fork of his repository on GitHub, list exactly 2 commands that will which when run in succession will allow this to happen.
Answer!
Do the following 1. Add remote `git remote add my-origin ` 2. Push change `git push my-origin `
- You are working on a branch and want to incorporate the changes made to the main branch. What command do you use to do this?
Answer!
`git pull origin main`
- How will you make sure that your name and email appears on every commit that you make?
Answer!
adding them to `git config` entries will be `user.name` and `user.email`