{"id":8575,"date":"2020-01-10T09:39:21","date_gmt":"2020-01-10T09:39:21","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=8575"},"modified":"2021-11-15T06:15:53","modified_gmt":"2021-11-15T06:15:53","slug":"git-interview-questions-and-answer-part-6","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/git-interview-questions-and-answer-part-6\/","title":{"rendered":"Git Interview Questions and Answer Part \u2013 7"},"content":{"rendered":"\n<p><strong>How to Compute object ID and optionally creates a blob from a file?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>git hash-object (Ans)<\/strong><\/li><li>git cat-file<\/li><li>git update-ref<\/li><li>git count-objects<\/li><\/ul>\n\n\n\n<p><strong>How to Update the object name stored in a ref safely?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>git hash-object<\/li><li>git cat-file<\/li><li><strong>git update-ref (Ans)<\/strong><\/li><li>git count-objects<\/li><\/ul>\n\n\n\n<p><strong>Which commands will Reference logs or record when the tips of branches and other references were updated in the local repository. <\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>git log<\/li><li><strong>git reflog (Ans)<\/strong><\/li><li>git update-ref<\/li><li>git count-objects<\/li><\/ul>\n\n\n\n<p><strong>git stores different types of objects in .git\/objects. Which is wrong objecst type?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>commit<\/li><li>tree<\/li><li>blob<\/li><li><strong>parent (Ans)<\/strong><\/li><\/ul>\n\n\n\n<p><strong>How to show the contents of the hashed files in .git\/objects?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>git show<\/li><li>git reflog<\/li><li>git log<\/li><li><strong>git cat-file (Ans)<\/strong><\/li><\/ul>\n\n\n\n<p><strong>How to shows us the type of the object represented by a particular hash?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>git cat-file -t (Ans)<\/strong><\/li><li>git cat-file -p<\/li><li>git cat-file -k<\/li><li>git cat-file -type<\/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>It just changes the parent in the commit file.<\/li><li>It changes the commit&#8217;s parent and its SHA- <\/li><li>None of these<\/li><li><strong>It copies over the commit to a new commit with a different parent and SHA-  (Ans)<\/strong><\/li><\/ul>\n\n\n\n<p><strong>What happens to unreachable objects in the database?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>They immediately get deleted.<\/li><li>You can never make an object unreachable in Git.<\/li><li>They stay there forever, in case you want to retrieve them.<\/li><li><strong>They can eventually get garbage-collecte- (Ans)<\/strong><\/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>Can an object in Git be safely modified?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>No: you might get the same SHA1 as another object.<\/li><li><strong>No: if you changed even one bit, then you&#8217;d get a different object with its own SHA-  (Ans)<\/strong><\/li><li>Yes: you can edit the content of the file that stores the object.<\/li><li>Yes: you can ask Git to generate a new SHA1 for the object.<\/li><\/ul>\n\n\n\n<p><strong>What are the four types of objects in the Git database?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Blobs, Trees, Commits and Versions<\/li><li>Files, Directories, Commits and Tags<\/li><li><strong>Blobs, Trees, Commits and Annotated Tags (Ans)<\/strong><\/li><li>Blobs, Trees, Commits and Branches<\/li><\/ul>\n\n\n\n<p><strong>What happens when you commit?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>The current branch changes, HEAD doesn&#8217;t. (Ans)<\/strong><\/li><li>HEAD changes, the current branch doesn&#8217;t.<\/li><li>Neither HEAD nor the current branch change.<\/li><li>Both HEAD and the current branch change.<\/li><\/ul>\n\n\n\n<p><strong>Which objects are created when you merge?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Zero or one commit and nothing else<\/li><li>Merges don&#8217;t create new objects.<\/li><li><strong>Zero or one commit, and possibly new trees and blobs (Ans)<\/strong><\/li><li>Exactly one commit and nothing else<\/li><\/ul>\n\n\n\n<p><strong>Where can HEAD point?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>To a branch, a commit, a tree, or a blob<\/li><li>To a branch<\/li><li><strong>To a branch or a commit (Ans)<\/strong><\/li><li>To a branch or nowhere<\/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 clone<\/li><li><strong>git fork (Ans)<\/strong><\/li><li>git push<\/li><li>git fetch<\/li><\/ul>\n\n\n\n<p><strong>Which objects in Git have a SHA1 hash?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Only Blobs and Trees<\/li><li><strong>Each object in the database (Ans)<\/strong><\/li><li>Each object in the database, and the same object can have multiple SHA1 hashes<\/li><li>Only Commits<\/li><\/ul>\n\n\n\n<p><strong>Can an object in Git be safely modified?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>No: if you changed even one bit, then you&#8217;d get a different object with its own SHA1. (Ans)<\/strong><\/li><li>Yes: you can edit the content of the file that stores the object.<\/li><li>Yes: you can ask Git to generate a new SHA1 for the object.<\/li><li>No: you might get the same SHA1 as another object<\/li><\/ul>\n\n\n\n<p><strong>Where does Git store the names of files and directories?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>In the object database, inside the trees that point to the objects (Ans)<\/strong><\/li><li>In the object database, inside the blobs and trees that store files and directories<\/li><li>Nowhere<\/li><li>In the \u201c.git\/links\u201d subdirectory<\/li><\/ul>\n\n\n\n<p><strong>What happens when you commit?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Both HEAD and the current branch change.<\/li><li>Neither HEAD nor the current branch change.<\/li><li>HEAD changes, the current branch doesn&#8217;t.<\/li><li><strong>The current branch changes, HEAD doesn&#8217;t. (Ans)<\/strong><\/li><\/ul>\n\n\n\n<p><strong>Which objects are created when you merge?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Merges don&#8217;t create new objects.<\/li><li>Exactly one commit and nothing else<\/li><li>Zero or one commit and nothing else<\/li><li><strong>Zero or one commit, and possibly new trees and blobs (Ans)<\/strong><\/li><\/ul>\n\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_19887\"><iframe loading=\"lazy\"  id=\"_ytid_70378\"  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_19887\"  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 class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>How to Compute object ID and optionally creates a blob from a file? git hash-object (Ans) git cat-file git update-ref git count-objects How to Update the object name stored in&#8230; <\/p>\n","protected":false},"author":1,"featured_media":8714,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[38],"tags":[160,5435,1915,5637],"class_list":["post-8575","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-git","tag-git","tag-objects","tag-particular","tag-safely"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/8575","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=8575"}],"version-history":[{"count":4,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/8575\/revisions"}],"predecessor-version":[{"id":25182,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/8575\/revisions\/25182"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/8714"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=8575"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=8575"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=8575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}