qmk_firmware/assets/newbs_git_resolving_merge_conflicts.md.72w3BRmm.js

16 lines
7.9 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { _ as _export_sfc, c as createElementBlock, o as openBlock, a8 as createStaticVNode } from "./chunks/framework.DyMmIvSC.js";
const __pageData = JSON.parse('{"title":"Resolving Merge Conflicts","description":"","frontmatter":{},"headers":[],"relativePath":"newbs_git_resolving_merge_conflicts.md","filePath":"newbs_git_resolving_merge_conflicts.md"}');
const _sfc_main = { name: "newbs_git_resolving_merge_conflicts.md" };
const _hoisted_1 = /* @__PURE__ */ createStaticVNode('<h1 id="resolving-merge-conflicts" tabindex="-1">Resolving Merge Conflicts <a class="header-anchor" href="#resolving-merge-conflicts" aria-label="Permalink to &quot;Resolving Merge Conflicts&quot;"></a></h1><p>Sometimes when your work in a branch takes a long time to complete, changes that have been made by others conflict with changes you have made to your branch when you open a pull request. This is called a <em>merge conflict</em>, and is what happens when multiple people edit the same parts of the same files.</p><div class="tip custom-block"><p class="custom-block-title">TIP</p><p>This document builds upon the concepts detailed in <a href="./newbs_git_using_your_master_branch">Your Fork&#39;s Master: Update Often, Commit Never</a>. If you are not familiar with that document, please read it first, then return here.</p></div><h2 id="rebasing-your-changes" tabindex="-1">Rebasing Your Changes <a class="header-anchor" href="#rebasing-your-changes" aria-label="Permalink to &quot;Rebasing Your Changes&quot;"></a></h2><p>A <em>rebase</em> is Git&#39;s way of taking changes that were applied at one point in the commit history, reversing them, and then applying the same changes at another point. In the case of a merge conflict, you can rebase your branch to grab the changes that were made between when you created your branch and the present time.</p><p>To start, run the following:</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span>git fetch upstream</span></span>\n<span class="line"><span>git rev-list --left-right --count HEAD...upstream/master</span></span></code></pre></div><p>The <code>git rev-list</code> command entered here returns the number of commits that differ between the current branch and QMK&#39;s master branch. We run <code>git fetch</code> first to make sure we have the refs that represent the current state of the upstream repo. The output of the <code>git rev-list</code> command entered returns two numbers:</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span>$ git rev-list --left-right --count HEAD...upstream/master</span></span>\n<span class="line"><span>7 35</span></span></code></pre></div><p>The first number represents the number of commits on the current branch since it was created, and the second number is the number of commits made to <code>upstream/master</code> since the current branch was created, and thus, the changes that are not recorded in the current branch.</p><p>Now that the current states of both the current branch and the upstream repo are known, we can start a rebase operation:</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span>git rebase upstream/master</span></span></code></pre></div><p>This tells Git to undo the commits on the current branch, and then reapply them against QMK&#39;s master branch.</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span>$ git rebase upstream/master</span></span>\n<span class="line"><span>First, rewinding head to replay your work on top of it...</span></span>\n<span class="line"><span>Applying: Commit #1</span></span>\n<span class="line"><span>Using index info to reconstruct a base tree...</span></span>\n<span class="line"><span>M conflicting_file_1.txt</span></span>\n<span class="line"><span>Falling back to patching base and 3-way merge...</span></span>\n<span class="line"><span>Auto-merging conflicting_file_1.txt</span></span>\n<span class="line"><span>CONFLICT (content): Merge conflict in conflicting_file_1.txt</span></span>\n<span class="line"><span>error: Failed to merge in the changes.</span></span>\n<span class="line"><span>hint: Use &#39;git am --show-current-patch&#39; to see the failed patch</span></span>\n<span class="line"><span>Patch failed at 0001 Commit #1</span></span>\n<span class="line"><span></span></span>\n<span class="line"><span>Resolve all conflicts manually, mark them as resolved with</span></span>\n<span class="line"><span>&quot;git add/rm &lt;conflicted_files&gt;&quot;, then run &quot;git rebase --continue&quot;.</span></span>\n<span class="line"><span>You can instead skip this commit: run &quot;git rebase --skip&quot;.</span></span>\n<span class="line"><span>To abort and get back to the state before &quot;git rebase&quot;, run &quot;git rebase --abort&quot;.</span></span></code></pre></div><p>This tells us that we have a merge conflict, and gives the name of the file with the conflict. Open the conflicting file in your text editor, and somewhere in the file, you&#39;ll find something like this:</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span>&lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD</span></span>\n<span class="line"><span>&lt;p&gt;For help with any issues, email us at support@webhost.us.&lt;/p&gt;</span></span>\n<span class="line"><span>=======</span></span>\n<span class="line"><span>&lt;p&gt;Need help? Email support@webhost.us.&lt;/p&gt;</span></span>\n<span class="line"><span>&gt;&gt;&gt;&gt;&gt;&gt;&gt; Commit #1</span></span></code></pre></div><p>The line <code>&lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD</code> marks the beginning of a merge conflict, and the <code>&gt;&gt;&gt;&gt;&gt;&gt;&gt; Commit #1</code> line marks the end, with the conflicting sections separated by <code>=======</code>. The part on the <code>HEAD</code> side is from the QMK master version of the file, and the part marked with the commit message is from the current branch and commit.</p><p>Because Git tracks <em>changes to files</em> rather than the contents of the files directly, if Git can&#39;t find the text that was in the file previous to the commit that was made, it won&#39;t know how to edit the file. Re-editing the file will solve the conflict. Make your changes, and then save the file.</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span>&lt;p&gt;Need help? Email support@webhost.us.&lt;/p&gt;</span></span></code></pre></div><p>Now run:</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span>git add conflicting_file_1.txt</span></span>\n<span class="line"><span>git rebase --continue</span></span></code></pre></div><p>Git logs the changes to the conflicting file, and continues applying the commits from our branch until it reaches the end.</p>', 22);
const _hoisted_23 = [
_hoisted_1
];
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return openBlock(), createElementBlock("div", null, _hoisted_23);
}
const newbs_git_resolving_merge_conflicts = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
export {
__pageData,
newbs_git_resolving_merge_conflicts as default
};