
{"id":196,"date":"2024-05-14T04:18:37","date_gmt":"2024-05-14T10:18:37","guid":{"rendered":"https:\/\/gitready.com\/?p=196"},"modified":"2024-05-29T04:25:31","modified_gmt":"2024-05-29T10:25:31","slug":"find-unmerged-commits","status":"publish","type":"post","link":"https:\/\/gitready.com\/intermediate\/2009\/04\/16\/find-unmerged-commits.html","title":{"rendered":"Find unmerged commits"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">As you&#8217;re progressing with development on a topic branch, you eventually reach a point where you need to merge your work back into the main development line. While graphical tools like gitk or GitX offer intuitive ways to identify unmerged commits, let&#8217;s explore how to achieve the same from the command line. Consider the following scenario:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you prefer the command line, you have several options available. One effective way to visualize this is by using git log, which offers a range of useful options:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git log --pretty=oneline --graph --all<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can also use the range syntax in git log to identify the commits that haven&#8217;t been merged:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git checkout master<br>git log ..42-adding-replies<br>git log master..42-adding-replies<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Another option is to use git cherry, which precisely identifies commits that aren&#8217;t in the specified branch. For instance, if you&#8217;re on the master branch, you can run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git cherry -v master 42-adding-replies<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This command tells you which commits are present in the 42-adding-replies branch but not in master. The -v option prints the commit message along with the SHA hash, making it easier to identify each commit. Additionally, you can provide an optional third argument to specify a starting point or limit for the comparison.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you&#8217;re not on the upstream branch and want to check what commits haven&#8217;t been merged into it, the process is simpler:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git checkout 42-adding-replies<br>git cherry master<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This command compares the commits in the current branch with those in master and lists the ones that haven&#8217;t been merged yet.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">An interesting aspect of git cherry is that it compares changesets rather than commit SHA hashes. This ensures accuracy, especially if you&#8217;ve modified the commit by adding a signoff or altering its parents in any way. You can rely on this command to accurately identify commits that haven&#8217;t been merged into your upstream branch. And remember, don&#8217;t confuse git cherry with cherry-pick, as they serve different purposes.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As you&#8217;re progressing with development on a topic branch, you eventually reach a point where you need to merge your work back into the main development line.<\/p>\n","protected":false},"author":2,"featured_media":197,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-196","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-intermediate"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Find unmerged commits<\/title>\n<meta name=\"description\" content=\"As you&#039;re progressing with development on a topic branch, you eventually reach a point where you need to merge your work back into the main development line.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gitready.com\/intermediate\/2009\/04\/16\/find-unmerged-commits.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Find unmerged commits\" \/>\n<meta property=\"og:description\" content=\"As you&#039;re progressing with development on a topic branch, you eventually reach a point where you need to merge your work back into the main development line.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gitready.com\/intermediate\/2009\/04\/16\/find-unmerged-commits.html\" \/>\n<meta property=\"og:site_name\" content=\"Gitready\" \/>\n<meta property=\"article:published_time\" content=\"2024-05-14T10:18:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-05-29T10:25:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/gitready.com\/wp-content\/uploads\/2024\/05\/code22.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1080\" \/>\n\t<meta property=\"og:image:height\" content=\"800\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Walsh Steven\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Walsh Steven\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/gitready.com\/intermediate\/2009\/04\/16\/find-unmerged-commits.html\",\"url\":\"https:\/\/gitready.com\/intermediate\/2009\/04\/16\/find-unmerged-commits.html\",\"name\":\"Find unmerged commits\",\"isPartOf\":{\"@id\":\"https:\/\/gitready.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/gitready.com\/intermediate\/2009\/04\/16\/find-unmerged-commits.html#primaryimage\"},\"image\":{\"@id\":\"https:\/\/gitready.com\/intermediate\/2009\/04\/16\/find-unmerged-commits.html#primaryimage\"},\"thumbnailUrl\":\"https:\/\/gitready.com\/wp-content\/uploads\/2024\/05\/code22.jpg\",\"datePublished\":\"2024-05-14T10:18:37+00:00\",\"dateModified\":\"2024-05-29T10:25:31+00:00\",\"author\":{\"@id\":\"https:\/\/gitready.com\/#\/schema\/person\/d07810fde7afa72f7f3bc0653cba4bc4\"},\"description\":\"As you're progressing with development on a topic branch, you eventually reach a point where you need to merge your work back into the main development line.\",\"breadcrumb\":{\"@id\":\"https:\/\/gitready.com\/intermediate\/2009\/04\/16\/find-unmerged-commits.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/gitready.com\/intermediate\/2009\/04\/16\/find-unmerged-commits.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/gitready.com\/intermediate\/2009\/04\/16\/find-unmerged-commits.html#primaryimage\",\"url\":\"https:\/\/gitready.com\/wp-content\/uploads\/2024\/05\/code22.jpg\",\"contentUrl\":\"https:\/\/gitready.com\/wp-content\/uploads\/2024\/05\/code22.jpg\",\"width\":1080,\"height\":800,\"caption\":\"code\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/gitready.com\/intermediate\/2009\/04\/16\/find-unmerged-commits.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/gitready.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Find unmerged commits\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/gitready.com\/#website\",\"url\":\"https:\/\/gitready.com\/\",\"name\":\"Gitready\",\"description\":\"GIT Learning Conference\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/gitready.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/gitready.com\/#\/schema\/person\/d07810fde7afa72f7f3bc0653cba4bc4\",\"name\":\"Walsh Steven\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/gitready.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f899b4aa85ad992cd9eb8290cf1d375fb1b8663f4546dd81bf5246de13138e95?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f899b4aa85ad992cd9eb8290cf1d375fb1b8663f4546dd81bf5246de13138e95?s=96&d=mm&r=g\",\"caption\":\"Walsh Steven\"},\"url\":\"https:\/\/gitready.com\/author\/steven-walsh\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Find unmerged commits","description":"As you're progressing with development on a topic branch, you eventually reach a point where you need to merge your work back into the main development line.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/gitready.com\/intermediate\/2009\/04\/16\/find-unmerged-commits.html","og_locale":"en_US","og_type":"article","og_title":"Find unmerged commits","og_description":"As you're progressing with development on a topic branch, you eventually reach a point where you need to merge your work back into the main development line.","og_url":"https:\/\/gitready.com\/intermediate\/2009\/04\/16\/find-unmerged-commits.html","og_site_name":"Gitready","article_published_time":"2024-05-14T10:18:37+00:00","article_modified_time":"2024-05-29T10:25:31+00:00","og_image":[{"width":1080,"height":800,"url":"https:\/\/gitready.com\/wp-content\/uploads\/2024\/05\/code22.jpg","type":"image\/jpeg"}],"author":"Walsh Steven","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Walsh Steven","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/gitready.com\/intermediate\/2009\/04\/16\/find-unmerged-commits.html","url":"https:\/\/gitready.com\/intermediate\/2009\/04\/16\/find-unmerged-commits.html","name":"Find unmerged commits","isPartOf":{"@id":"https:\/\/gitready.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/gitready.com\/intermediate\/2009\/04\/16\/find-unmerged-commits.html#primaryimage"},"image":{"@id":"https:\/\/gitready.com\/intermediate\/2009\/04\/16\/find-unmerged-commits.html#primaryimage"},"thumbnailUrl":"https:\/\/gitready.com\/wp-content\/uploads\/2024\/05\/code22.jpg","datePublished":"2024-05-14T10:18:37+00:00","dateModified":"2024-05-29T10:25:31+00:00","author":{"@id":"https:\/\/gitready.com\/#\/schema\/person\/d07810fde7afa72f7f3bc0653cba4bc4"},"description":"As you're progressing with development on a topic branch, you eventually reach a point where you need to merge your work back into the main development line.","breadcrumb":{"@id":"https:\/\/gitready.com\/intermediate\/2009\/04\/16\/find-unmerged-commits.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gitready.com\/intermediate\/2009\/04\/16\/find-unmerged-commits.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/gitready.com\/intermediate\/2009\/04\/16\/find-unmerged-commits.html#primaryimage","url":"https:\/\/gitready.com\/wp-content\/uploads\/2024\/05\/code22.jpg","contentUrl":"https:\/\/gitready.com\/wp-content\/uploads\/2024\/05\/code22.jpg","width":1080,"height":800,"caption":"code"},{"@type":"BreadcrumbList","@id":"https:\/\/gitready.com\/intermediate\/2009\/04\/16\/find-unmerged-commits.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gitready.com\/"},{"@type":"ListItem","position":2,"name":"Find unmerged commits"}]},{"@type":"WebSite","@id":"https:\/\/gitready.com\/#website","url":"https:\/\/gitready.com\/","name":"Gitready","description":"GIT Learning Conference","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gitready.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/gitready.com\/#\/schema\/person\/d07810fde7afa72f7f3bc0653cba4bc4","name":"Walsh Steven","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/gitready.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/f899b4aa85ad992cd9eb8290cf1d375fb1b8663f4546dd81bf5246de13138e95?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f899b4aa85ad992cd9eb8290cf1d375fb1b8663f4546dd81bf5246de13138e95?s=96&d=mm&r=g","caption":"Walsh Steven"},"url":"https:\/\/gitready.com\/author\/steven-walsh\/"}]}},"_links":{"self":[{"href":"https:\/\/gitready.com\/wp-json\/wp\/v2\/posts\/196","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gitready.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gitready.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gitready.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/gitready.com\/wp-json\/wp\/v2\/comments?post=196"}],"version-history":[{"count":1,"href":"https:\/\/gitready.com\/wp-json\/wp\/v2\/posts\/196\/revisions"}],"predecessor-version":[{"id":198,"href":"https:\/\/gitready.com\/wp-json\/wp\/v2\/posts\/196\/revisions\/198"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gitready.com\/wp-json\/wp\/v2\/media\/197"}],"wp:attachment":[{"href":"https:\/\/gitready.com\/wp-json\/wp\/v2\/media?parent=196"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gitready.com\/wp-json\/wp\/v2\/categories?post=196"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gitready.com\/wp-json\/wp\/v2\/tags?post=196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}