{"id":8580,"date":"2020-01-10T10:04:56","date_gmt":"2020-01-10T10:04:56","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=8580"},"modified":"2021-11-15T06:16:11","modified_gmt":"2021-11-15T06:16:11","slug":"git-interview-questions-and-answer-part-7","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/git-interview-questions-and-answer-part-7\/","title":{"rendered":"Git Interview Questions and Answer Part \u2013 10"},"content":{"rendered":"\n<p><strong>Where can HEAD point?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>To a branch<\/li><li>To a branch or nowhere<\/li><li><strong>To a branch or a commit (Ans)<\/strong><\/li><li>To a branch, a commit, a tree, or a blob<\/li><\/ul>\n\n\n\n<p><strong>How does &#8220;git rebase&#8221; move an existing commit?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>It copies over the commit to a new commit with a different parent and SHA1. (Ans)<\/strong><\/li><li>None of these<\/li><li>It just changes the parent in the commit file.<\/li><li>It changes the commit&#8217;s parent and its SHA1.<\/li><\/ul>\n\n\n\n<p><strong>What&#8217;s one difference between merges and rebases?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Rebases change history, merges don&#8217;t. (Ans)<\/strong><\/li><li>None of these<\/li><li>Rebases create commits with multiple parents, merges don&#8217;t.<\/li><li>Merges create a new commit object, rebases don&#8217;t<\/li><\/ul>\n\n\n\n<p><strong>What&#8217;s a &#8220;pull&#8221;?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>A &#8220;merge&#8221; followed by a &#8220;push&#8221;<\/li><li>A &#8220;push&#8221; followed by a &#8220;merge&#8221;<\/li><li>A &#8220;fetch&#8221; followed by a &#8220;push&#8221;<\/li><li><strong>A &#8220;fetch&#8221; followed by a &#8220;merge&#8221; (Ans)<\/strong><\/li><\/ul>\n\n\n\n<p><strong>Which of these is not a Git command?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>git fetch<\/li><li><strong>git fork (Ans)<\/strong><\/li><li>git push<\/li><li>git clone<\/li><\/ul>\n\n\n\n<p><strong>The setting, core.autocrlf, configures:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>automatic addition of line breaks to commit messages.<\/li><li>autocorrection of spelling errors in commit messages.<\/li><li><strong>conversion of line endings between the repository and working copy. (Ans)<\/strong><\/li><li>stripping extra line breaks from the end of files.<\/li><\/ul>\n\n\n\n<p><strong>Which command creates a local git repository?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>git localrepo<\/li><li><strong>git init (Ans)<\/strong><\/li><li>git repo<\/li><li>git initrepo<\/li><\/ul>\n\n\n\n<p><strong>Performing a git pull is equivalent to a git fetch followed by:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>git merge (Ans)<\/strong><\/li><li>git rebase<\/li><li>git cherry-pick<\/li><li>git reset &#8211;hard<\/li><\/ul>\n\n\n\n<p><strong>Cherry-picking a commit will:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>apply only that commit to the current branch. (Ans)<\/strong><\/li><li>remove the commit from its source branch and apply it to the current branch.<\/li><li>apply that commit and all subsequent commit to the current branch.<\/li><li>apply that commit and all previous commits to the current branch.<\/li><\/ul>\n\n\n\n<p><strong>The advantage of a DVCs is:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>full local history<\/li><li>easy backups<\/li><li><strong>all of these (Ans)<\/strong><\/li><li>reliable branching\/merging<\/li><li>different topologies<\/li><\/ul>\n\n\n\n<p><strong>To remove and discard the changes from the last commit on your current branch, you should use:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>git reset &#8211;soft HEAD<\/li><li>git revert HEAD<\/li><li>git revert HEAD~1<\/li><li>git reset &#8211;hard HEAD<\/li><li><strong> git reset &#8211;hard HEAD~1 (Ans)<\/strong><\/li><\/ul>\n\n\n\n<p><strong>Which URL style should you use if you want to avoid using passwords?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>http:\/\/github.com\/username\/repository.git<\/li><li><strong>git@github.com:username\/repository.git (Ans)<\/strong><\/li><li>git:\/\/github.com\/username\/repository.git<\/li><li>https:\/\/github.com\/username\/repository.git<\/li><\/ul>\n\n\n\n<p><strong>Given an unmerged feature branch, feature1, what is the effect of running &#8220;git branch -d feature1&#8221;?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Deletion of feature1 will fail silently<\/li><li><strong>feature1 will not be deleted and an error message will be displayed (Ans)<\/strong><\/li><li>Git will display the prompt &#8220;Unmerged changes. Confirm delete? (y\/N)&#8221;<\/li><li>feature1 will be deleted<\/li><\/ul>\n\n\n\n<p><strong>User-level configuration in Git can be modified using:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>git config &#8211;system<\/li><li>git config<\/li><li>git config &#8211;user<\/li><li><strong>git config &#8211;global (Ans)<\/strong><\/li><\/ul>\n\n\n\n<p><strong>Which file lists the files and directories that should not be committed to the repository?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>.git\/config<\/li><li>.gitnocommit<\/li><li>.gitattributes<\/li><li><strong>.gitignore (Ans)<\/strong><\/li><\/ul>\n\n\n\n<p><strong>What feature in Git allows you to become more efficient at the command line?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Speech recognition<\/li><li>Keyboard shortcuts<\/li><li>Snippets<\/li><li><strong>Aliases (Ans)<\/strong><\/li><\/ul>\n\n\n\n<p><strong>When is a commit A said to be reachable from another commit B?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>When B is an ancestor of A<\/li><li>When A is the direct parent of B<\/li><li>When A and B are patch equivalent<\/li><li><strong>When A is an ancestor of B (Ans)<\/strong><\/li><\/ul>\n\n\n\n<p><strong>How can Git calculate patches on the fly?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>It&#8217;s really good at math.<\/li><li>It uses the patience algorithm.<\/li><li><strong>It stores the entire files in the working directory for each commit. (Ans)<\/strong><\/li><li>It stores deltas between files in the working directory.<\/li><\/ul>\n\n\n\n<p><strong>What is the difference between the -S and -G options of git log?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>-S searches for matching lines that are removed, while -G searches for lines that are added.<\/li><li>-S searches for matching lines that are either added, removed, or modified, while -G only includes lines that are modified.<\/li><li><strong>-S searches for matching lines that are either added or removed, while -G also includes lines that are modifie- (Ans)<\/strong><\/li><li>-S searches for matching lines that are either added or removed, while -G also includes lines that are modified.<\/li><\/ul>\n\n\n\n<p><strong>In which scenario is git rerere useful?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>When dealing with complex merge conflicts<\/li><li>When merging more than two branches<\/li><li>When dealing with a lot of different merge conflicts<\/li><li><strong>When dealing with the same merge conflict more than once (Ans)<\/strong><\/li><\/ul>\n\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_63071\"><figure class=\"wp-block-embed wp-block-embed-youtube is-type-video is-provider-youtube epyt-figure\"><div class=\"wp-block-embed__wrapper\"><iframe loading=\"lazy\"  id=\"_ytid_60132\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  data-epytgalleryid=\"epyt_gallery_63071\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><\/div><\/figure><div class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Where can HEAD point? To a branch To a branch or nowhere To a branch or a commit (Ans) To a branch, a commit, a tree, or a blob How does &#8220;git rebase&#8221; move an existing commit? It copies over the commit to a new commit with a different parent and SHA1. (Ans) None of&#8230;<\/p>\n","protected":false},"author":1,"featured_media":8713,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[38],"tags":[5023,160,5638,5111],"class_list":["post-8580","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-git","tag-commit","tag-git","tag-head-point","tag-pull"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/8580","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=8580"}],"version-history":[{"count":3,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/8580\/revisions"}],"predecessor-version":[{"id":25183,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/8580\/revisions\/25183"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/8713"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=8580"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=8580"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=8580"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}