<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://wiki.bathcs.com/index.php?action=history&amp;feed=atom&amp;title=Git%2FAdvanced</id>
	<title>Git/Advanced - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.bathcs.com/index.php?action=history&amp;feed=atom&amp;title=Git%2FAdvanced"/>
	<link rel="alternate" type="text/html" href="https://wiki.bathcs.com/index.php?title=Git/Advanced&amp;action=history"/>
	<updated>2026-08-26T06:43:53Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.46.0</generator>
	<entry>
		<id>https://wiki.bathcs.com/index.php?title=Git/Advanced&amp;diff=148&amp;oldid=prev</id>
		<title>Pcs47: Recommend --force-with-lease (https://gitlab.bath.ac.uk/cs/services/wiki/-/work_items/33)</title>
		<link rel="alternate" type="text/html" href="https://wiki.bathcs.com/index.php?title=Git/Advanced&amp;diff=148&amp;oldid=prev"/>
		<updated>2026-06-08T12:43:50Z</updated>

		<summary type="html">&lt;p&gt;Recommend --force-with-lease (https://gitlab.bath.ac.uk/cs/services/wiki/-/work_items/33)&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw-interface=&quot;&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en-GB&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 12:43, 8 June 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l46&quot;&gt;Line 46:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 46:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;They both do the same thing of reverting the changes from the given commit. But the difference is, &amp;lt;code&amp;gt;revert&amp;lt;/code&amp;gt; will create a new commit (therefore you can just run &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt; or merging without any issues), whereas &amp;lt;code&amp;gt;reset&amp;lt;/code&amp;gt; will remove those commits outright.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;They both do the same thing of reverting the changes from the given commit. But the difference is, &amp;lt;code&amp;gt;revert&amp;lt;/code&amp;gt; will create a new commit (therefore you can just run &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt; or merging without any issues), whereas &amp;lt;code&amp;gt;reset&amp;lt;/code&amp;gt; will remove those commits outright.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;When resetting, the tree (simply, the list of commits) itself is altered. This means that when pushing to a repo which already contains that commit, you have to use &amp;lt;code&amp;gt;git push --force&amp;lt;/code&amp;gt;. This will cause anyone else working on the same branch to lose their changes, as they are forced to run &amp;lt;code&amp;gt;git pull --force&amp;lt;/code&amp;gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;When resetting, the tree (simply, the list of commits) itself is altered. This means that when pushing to a repo which already contains that commit, you have to use &amp;lt;code&amp;gt;git push --force&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;-with-lease&lt;/ins&gt;&amp;lt;/code&amp;gt;. This will cause anyone else working on the same branch to lose their changes, as they are forced to run &amp;lt;code&amp;gt;git pull --force&amp;lt;/code&amp;gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;. There also exists &amp;lt;code&amp;gt;git push --force&amp;lt;/code&amp;gt;, but &amp;lt;code&amp;gt;--force-with-lease&amp;lt;/code&amp;gt; won&#039;t apply changes if the remote has commits that you don&#039;t have locally. Therefore, &amp;lt;code&amp;gt;--force-with-lease&amp;lt;/code&amp;gt; is preferred&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This command is dangerous so make sure you check everything before using it as it forces the upstream to be exactly like your local branch. So if you accidentally removed the wrong commit, you cannot easily get it back.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This command is dangerous so make sure you check everything before using it as it forces the upstream to be exactly like your local branch. So if you accidentally removed the wrong commit, you cannot easily get it back.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l64&quot;&gt;Line 64:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 64:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;git rebase main&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;git rebase main&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{Note|text=&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{Note|text=&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;As we are changing the structure of the commit tree, you must then run &amp;lt;code&amp;gt;git push --force&amp;lt;/code&amp;gt; once you are 100% happy none of your changes have been lost.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;As we are changing the structure of the commit tree, you must then run &amp;lt;code&amp;gt;git push --force&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;-with-lease&lt;/ins&gt;&amp;lt;/code&amp;gt; once you are 100% happy none of your changes have been lost.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;As usual, if there is anyone else using your current branch, you shouldn’t do this.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;As usual, if there is anyone else using your current branch, you shouldn’t do this.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l196&quot;&gt;Line 196:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 196:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Merging ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Merging ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Normally merging is done via the interface on the remote repository system you are using. However it can be done in the command line as well (it can also be used in place of &amp;lt;code&amp;gt;rebase&amp;lt;/code&amp;gt; so you don’t have to use the dangerous &amp;lt;code&amp;gt;git push --force&amp;lt;/code&amp;gt;).&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Normally merging is done via the interface on the remote repository system you are using. However it can be done in the command line as well (it can also be used in place of &amp;lt;code&amp;gt;rebase&amp;lt;/code&amp;gt; so you don’t have to use the dangerous &amp;lt;code&amp;gt;git push --force&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;-with-lease&lt;/ins&gt;&amp;lt;/code&amp;gt;).&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;It copies all the commits which have been added on a branch to the branch you are currently on (e.g. &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;).&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;It copies all the commits which have been added on a branch to the branch you are currently on (e.g. &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;).&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Pcs47</name></author>
	</entry>
	<entry>
		<id>https://wiki.bathcs.com/index.php?title=Git/Advanced&amp;diff=143&amp;oldid=prev</id>
		<title>Hw2210: /* See also */ Include Git in pages</title>
		<link rel="alternate" type="text/html" href="https://wiki.bathcs.com/index.php?title=Git/Advanced&amp;diff=143&amp;oldid=prev"/>
		<updated>2026-06-05T13:56:41Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;See also: &lt;/span&gt; Include Git in pages&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw-interface=&quot;&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en-GB&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 13:56, 5 June 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l271&quot;&gt;Line 271:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 271:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== See also ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== See also ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{Special:PrefixIndex|prefix=Git&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;/&lt;/del&gt;|namespace=0|hideredirects=1}}&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{Special:PrefixIndex|prefix=Git|namespace=0|hideredirects=1}}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Tutorial]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Tutorial]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Hw2210</name></author>
	</entry>
	<entry>
		<id>https://wiki.bathcs.com/index.php?title=Git/Advanced&amp;diff=138&amp;oldid=prev</id>
		<title>Hw2210: /* See also */ Don&#039;t show redirects</title>
		<link rel="alternate" type="text/html" href="https://wiki.bathcs.com/index.php?title=Git/Advanced&amp;diff=138&amp;oldid=prev"/>
		<updated>2026-06-05T13:54:26Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;See also: &lt;/span&gt; Don&amp;#039;t show redirects&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw-interface=&quot;&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en-GB&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 13:54, 5 June 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l271&quot;&gt;Line 271:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 271:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== See also ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== See also ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{Special:PrefixIndex|prefix=Git|namespace=0}}&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{Special:PrefixIndex|prefix=Git&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;/&lt;/ins&gt;|namespace=0&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;|hideredirects=1&lt;/ins&gt;}}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Tutorial]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Tutorial]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Hw2210</name></author>
	</entry>
	<entry>
		<id>https://wiki.bathcs.com/index.php?title=Git/Advanced&amp;diff=134&amp;oldid=prev</id>
		<title>Hw2210: /* Stashing */ Clarify uses for switch and checkout within stashing</title>
		<link rel="alternate" type="text/html" href="https://wiki.bathcs.com/index.php?title=Git/Advanced&amp;diff=134&amp;oldid=prev"/>
		<updated>2026-06-05T11:55:42Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Stashing: &lt;/span&gt; Clarify uses for switch and checkout within stashing&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw-interface=&quot;&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en-GB&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 11:55, 5 June 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l34&quot;&gt;Line 34:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 34:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{Note|type=reminder|text=&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{Note|type=reminder|text=&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;GUI tools e.g. lazygit or VSCode (with git extension pack) normally have a better interface for adding and removing stashes - so probably use that instead.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;GUI tools e.g. lazygit or VSCode (with git extension pack) normally have a better interface for adding and removing stashes - so probably use that instead.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;}}&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;}}This is &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;usually &lt;/ins&gt;used &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;with &amp;lt;code&amp;gt;git &lt;/ins&gt;switch&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/code&amp;gt; or &lt;/ins&gt;&amp;lt;code&amp;gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;git checkout&lt;/ins&gt;&amp;lt;/code&amp;gt; to &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;allow you to switch branches when you still have uncommitted changes that may conflict.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This is &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;commonly &lt;/del&gt;used &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;to &lt;/del&gt;switch &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;branches (however the new &lt;/del&gt;&amp;lt;code&amp;gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;switch&lt;/del&gt;&amp;lt;/code&amp;gt; &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;subcommand is designed &lt;/del&gt;to &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;replace this)&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Reverting vs Resetting ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Reverting vs Resetting ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Hw2210</name></author>
	</entry>
	<entry>
		<id>https://wiki.bathcs.com/index.php?title=Git/Advanced&amp;diff=85&amp;oldid=prev</id>
		<title>Hw2210: Update broken links</title>
		<link rel="alternate" type="text/html" href="https://wiki.bathcs.com/index.php?title=Git/Advanced&amp;diff=85&amp;oldid=prev"/>
		<updated>2026-06-03T20:43:41Z</updated>

		<summary type="html">&lt;p&gt;Update broken links&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw-interface=&quot;&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en-GB&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 20:43, 3 June 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l20&quot;&gt;Line 20:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 20:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Stashing is used when you want to record the current state of the working directory and the index, but want to go back to a clean working directory.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Stashing is used when you want to record the current state of the working directory and the index, but want to go back to a clean working directory.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;It allows you to set aside some changes for later or just never commit them (without altering the [[Git/Special &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Files&lt;/del&gt;#Gitignore|&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file]]).&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;It allows you to set aside some changes for later or just never commit them (without altering the [[Git/Special &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;files&lt;/ins&gt;#Gitignore|&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file]]).&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;By stashing your changes, they will be removed so you can no longer see them, but you can always &amp;lt;code&amp;gt;pop&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;apply&amp;lt;/code&amp;gt; the stash to get the back at any point.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;By stashing your changes, they will be removed so you can no longer see them, but you can always &amp;lt;code&amp;gt;pop&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;apply&amp;lt;/code&amp;gt; the stash to get the back at any point.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l209&quot;&gt;Line 209:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 209:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;                           # more&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;                           # more&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;git push&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;git push&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Conflicts can still happen, see [[#dealing-with-conflicts|above]] for more information about how to manage them.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Conflicts can still happen, see [[&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Git/Advanced&lt;/ins&gt;#dealing-with-conflicts|above]] for more information about how to manage them.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{Note|text=&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{Note|text=&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Hw2210</name></author>
	</entry>
	<entry>
		<id>https://wiki.bathcs.com/index.php?title=Git/Advanced&amp;diff=81&amp;oldid=prev</id>
		<title>Hw2210: Add see also section</title>
		<link rel="alternate" type="text/html" href="https://wiki.bathcs.com/index.php?title=Git/Advanced&amp;diff=81&amp;oldid=prev"/>
		<updated>2026-06-03T19:28:44Z</updated>

		<summary type="html">&lt;p&gt;Add see also section&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw-interface=&quot;&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en-GB&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 19:28, 3 June 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l271&quot;&gt;Line 271:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 271:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* If you have setup a strict mode with signing, you cannot commit if you loose access to your signing key&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* If you have setup a strict mode with signing, you cannot commit if you loose access to your signing key&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* When rebasing your changes, you have to resign all the commits (meaning you are the only one who can do it)&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* When rebasing your changes, you have to resign all the commits (meaning you are the only one who can do it)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;== See also ==&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;{{Special:PrefixIndex|prefix=Git|namespace=0}}&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:Tutorial]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Hw2210</name></author>
	</entry>
	<entry>
		<id>https://wiki.bathcs.com/index.php?title=Git/Advanced&amp;diff=68&amp;oldid=prev</id>
		<title>Hw2210: Translate from boss.bathcs.com</title>
		<link rel="alternate" type="text/html" href="https://wiki.bathcs.com/index.php?title=Git/Advanced&amp;diff=68&amp;oldid=prev"/>
		<updated>2026-06-03T18:45:12Z</updated>

		<summary type="html">&lt;p&gt;Translate from boss.bathcs.com&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Git is a really powerful command line tool when you start looking into the advanced things you can do, but when maintaining or developing a project, you are probably not going to touch most of them. This is a list of ones which I use on a regular basis.&lt;br /&gt;
&lt;br /&gt;
It’s important to note that the more advanced commands can have quite powerful functions which can lose code if used incorrectly. However, in most cases git caches a significant amount, so if you lose a commit or some changes, &amp;#039;&amp;#039;&amp;#039;don’t panic&amp;#039;&amp;#039;&amp;#039; and look up your issue (someone has done this before and found a way to get the changes back).&lt;br /&gt;
&lt;br /&gt;
== More on Commit IDs ==&lt;br /&gt;
&lt;br /&gt;
Where it says to use the &amp;lt;code&amp;gt;commit-id&amp;lt;/code&amp;gt;, there are different inputs you can use to specify multiple commits easily.&lt;br /&gt;
&lt;br /&gt;
Let A and B be the ids for two different commits. To reference a range you can do:&lt;br /&gt;
&lt;br /&gt;
* A to B (including A): &amp;lt;code&amp;gt;A^..B&amp;lt;/code&amp;gt;&lt;br /&gt;
* A to B (excluding A): &amp;lt;code&amp;gt;A..B&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or you can specify the last &amp;lt;code&amp;gt;X&amp;lt;/code&amp;gt; commits:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;HEAD~X&amp;lt;/code&amp;gt; e.g. &amp;lt;code&amp;gt;git reset --soft HEAD~4&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Stashing ==&lt;br /&gt;
&lt;br /&gt;
Stashing is used when you want to record the current state of the working directory and the index, but want to go back to a clean working directory.&lt;br /&gt;
&lt;br /&gt;
It allows you to set aside some changes for later or just never commit them (without altering the [[Git/Special Files#Gitignore|&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file]]).&lt;br /&gt;
&lt;br /&gt;
By stashing your changes, they will be removed so you can no longer see them, but you can always &amp;lt;code&amp;gt;pop&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;apply&amp;lt;/code&amp;gt; the stash to get the back at any point.&lt;br /&gt;
&lt;br /&gt;
=== Commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;git stash       # Stash current unstaged (but tracked) changes&lt;br /&gt;
git stash apply # Restore the last stash without deleting it&lt;br /&gt;
git stash pop   # Restore the last stash and delete it&lt;br /&gt;
git stash list  # List the stashed changes&lt;br /&gt;
git stash show  # Inspect the stashed changes&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Note|type=reminder|text=&lt;br /&gt;
GUI tools e.g. lazygit or VSCode (with git extension pack) normally have a better interface for adding and removing stashes - so probably use that instead.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
This is commonly used to switch branches (however the new &amp;lt;code&amp;gt;switch&amp;lt;/code&amp;gt; subcommand is designed to replace this)&lt;br /&gt;
&lt;br /&gt;
== Reverting vs Resetting ==&lt;br /&gt;
&lt;br /&gt;
To either reset or revert, you need the git commit hash id (or the start of it), this can be done via &amp;lt;code&amp;gt;git log&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Once you have that, the interface is quite similar:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;git reset commit-id&lt;br /&gt;
git revert commit-id&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
They both do the same thing of reverting the changes from the given commit. But the difference is, &amp;lt;code&amp;gt;revert&amp;lt;/code&amp;gt; will create a new commit (therefore you can just run &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt; or merging without any issues), whereas &amp;lt;code&amp;gt;reset&amp;lt;/code&amp;gt; will remove those commits outright.&lt;br /&gt;
&lt;br /&gt;
When resetting, the tree (simply, the list of commits) itself is altered. This means that when pushing to a repo which already contains that commit, you have to use &amp;lt;code&amp;gt;git push --force&amp;lt;/code&amp;gt;. This will cause anyone else working on the same branch to lose their changes, as they are forced to run &amp;lt;code&amp;gt;git pull --force&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This command is dangerous so make sure you check everything before using it as it forces the upstream to be exactly like your local branch. So if you accidentally removed the wrong commit, you cannot easily get it back.&lt;br /&gt;
&lt;br /&gt;
=== Extra options ===&lt;br /&gt;
&lt;br /&gt;
With &amp;lt;code&amp;gt;reset&amp;lt;/code&amp;gt; you also have extra options which you may find useful. You can either use &amp;lt;code&amp;gt;--soft&amp;lt;/code&amp;gt; (Put all the changes of the commit in staged) or &amp;lt;code&amp;gt;--hard&amp;lt;/code&amp;gt; (which is the default, just forget all changes).&lt;br /&gt;
&lt;br /&gt;
With &amp;lt;code&amp;gt;revert&amp;lt;/code&amp;gt; you can use &amp;lt;code&amp;gt;--no-commit&amp;lt;/code&amp;gt; which will put the inverse of the changes in staged (and not create a new commit). This allows you to add multiple reverts or more changes in it.&lt;br /&gt;
&lt;br /&gt;
== Rebasing ==&lt;br /&gt;
&lt;br /&gt;
Rebasing is used when commits have been added to &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; and you want to bring them to your branch (with was branched off of &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
To rebase off of main (when you are in your branch), you can run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;git rebase main&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
{{Note|text=&lt;br /&gt;
As we are changing the structure of the commit tree, you must then run &amp;lt;code&amp;gt;git push --force&amp;lt;/code&amp;gt; once you are 100% happy none of your changes have been lost.&lt;br /&gt;
&lt;br /&gt;
As usual, if there is anyone else using your current branch, you shouldn’t do this.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
The steps it is takes are:&lt;br /&gt;
&lt;br /&gt;
* Temporarily reset all your commits which you added to this branch&lt;br /&gt;
* Apply all the new commits in &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; (or the given branch)&lt;br /&gt;
* Re-apply all of your commits&lt;br /&gt;
&lt;br /&gt;
=== Dealing with Conflicts ===&lt;br /&gt;
&lt;br /&gt;
Sometimes there may be conflicting changes from the changes added to main (e.g. you’ve changed the same line as another change).&lt;br /&gt;
&lt;br /&gt;
This is when it gets quite confusing and dangerous.&lt;br /&gt;
&lt;br /&gt;
If this happens, git will print out an error, saying what files are are in conflict and where to find them.&lt;br /&gt;
&lt;br /&gt;
If you run &amp;lt;code&amp;gt;git status&amp;lt;/code&amp;gt; you will see that some files are staged and some are not. The idea for these are:&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Staged files&amp;#039;&amp;#039;&amp;#039;: These are the files which are not conflicting and will be committed on &amp;lt;code&amp;gt;git rebase --continue&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Unstaged files&amp;#039;&amp;#039;&amp;#039;: These are the files with conflicts&lt;br /&gt;
&lt;br /&gt;
If you open one of the conflicting files you will find that git has altered it where the conflicts are.&lt;br /&gt;
&lt;br /&gt;
The format is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;txt&amp;quot;&amp;gt;&amp;amp;lt;&amp;amp;lt;&amp;amp;lt;&amp;amp;lt;&amp;amp;lt;&amp;amp;lt;&amp;amp;lt; HEAD&lt;br /&gt;
- Auto writing README&lt;br /&gt;
- A cool logo - hw&lt;br /&gt;
- who&amp;#039;s the above guy?&lt;br /&gt;
=======&lt;br /&gt;
- something&lt;br /&gt;
- A cool logo - hw&lt;br /&gt;
- other&lt;br /&gt;
&amp;amp;gt;&amp;amp;gt;&amp;amp;gt;&amp;amp;gt;&amp;amp;gt;&amp;amp;gt;&amp;amp;gt; 8f309e1 (Test commit)&amp;lt;/pre&amp;gt;&lt;br /&gt;
{{Note|text= class=&amp;quot;note&amp;quot;&amp;gt;&lt;br /&gt;
VSCode has its own custom interface for this [https://code.visualstudio.com/docs/sourcecontrol/overview#_3way-merge-editor read more here]&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
You will see the changes you made are below the &amp;lt;code&amp;gt;=======&amp;lt;/code&amp;gt; and the (updated) upstream code in &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; is above it.&lt;br /&gt;
&lt;br /&gt;
What you have to do is, for each of these conflicts, to choose which one to keep (or create a mixture). To do this, you just remove everything that shouldn’t be there (which includes &amp;lt;code&amp;gt;&amp;amp;lt;&amp;amp;lt;&amp;amp;lt;&amp;amp;lt;&amp;amp;lt;&amp;amp;lt;&amp;amp;lt; HEAD&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;=======&amp;lt;/code&amp;gt;, etc). For example, in this case it should result in:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;txt&amp;quot;&amp;gt;- Auto writing README&lt;br /&gt;
- something&lt;br /&gt;
- A cool logo - hw&lt;br /&gt;
- other&lt;br /&gt;
- who&amp;#039;s the above guy?&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once you are happy an entire file is now conflict-free and correct, you can stage it.&lt;br /&gt;
&lt;br /&gt;
Then once there are no unstaged files left you can run &amp;lt;code&amp;gt;git rebase --continue&amp;lt;/code&amp;gt;, which will save the changes under the original commit (sometimes it will ask you to confirm the commit message with your editor, you can just save and exit it).&lt;br /&gt;
&lt;br /&gt;
Once you have finished rebasing, make sure to test that your code still works. It’s common for code to break after rebasing due to unexpected changes made by someone else.&lt;br /&gt;
&lt;br /&gt;
=== Interactive Rebase ===&lt;br /&gt;
&lt;br /&gt;
Interactive rebasing is one of the most powerful and fun commands ever. However it comes with the downside of it being quite dangerous.&lt;br /&gt;
&lt;br /&gt;
It is used for reorganising a merge request and managing commits to clean up the git log.&lt;br /&gt;
&lt;br /&gt;
To use it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;git rebase -i HEAD~X&lt;br /&gt;
# Or interactive rebase off of main&lt;br /&gt;
git rebase -i main&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
This should bring up your default text editor with a list of commits with a list of commands at the end, which looks like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;pick af44004 Annoying rebasing commit&lt;br /&gt;
pick ceb4454 Add quote from Varnie&lt;br /&gt;
pick 1f156e8 Test commit&lt;br /&gt;
&lt;br /&gt;
# Rebase 315c076..1f156e8 onto 315c076 (3 commands)&lt;br /&gt;
#&lt;br /&gt;
# Commands:&lt;br /&gt;
# p, pick &amp;amp;lt;commit&amp;amp;gt; = use commit&lt;br /&gt;
# r, reword &amp;amp;lt;commit&amp;amp;gt; = use commit, but edit the commit message&lt;br /&gt;
# e, edit &amp;amp;lt;commit&amp;amp;gt; = use commit, but stop for amending&lt;br /&gt;
# s, squash &amp;amp;lt;commit&amp;amp;gt; = use commit, but meld into previous commit&lt;br /&gt;
# f, fixup [-C | -c] &amp;amp;lt;commit&amp;amp;gt; = like &amp;amp;quot;squash&amp;amp;quot; but keep only the previous&lt;br /&gt;
#                    commit&amp;#039;s log message, unless -C is used, in which case&lt;br /&gt;
#                    keep only this commit&amp;#039;s message; -c is same as -C but&lt;br /&gt;
#                    opens the editor&lt;br /&gt;
# x, exec &amp;amp;lt;command&amp;amp;gt; = run command (the rest of the line) using shell&lt;br /&gt;
# b, break = stop here (continue rebase later with &amp;#039;git rebase --continue&amp;#039;)&lt;br /&gt;
# d, drop &amp;amp;lt;commit&amp;amp;gt; = remove commit&lt;br /&gt;
# l, label &amp;amp;lt;label&amp;amp;gt; = label current HEAD with a name&lt;br /&gt;
# t, reset &amp;amp;lt;label&amp;amp;gt; = reset HEAD to a label&lt;br /&gt;
# m, merge [-C &amp;amp;lt;commit&amp;amp;gt; | -c &amp;amp;lt;commit&amp;amp;gt;] &amp;amp;lt;label&amp;amp;gt; [# &amp;amp;lt;oneline&amp;amp;gt;]&lt;br /&gt;
#         create a merge commit using the original merge commit&amp;#039;s&lt;br /&gt;
#         message (or the oneline, if no original merge commit was&lt;br /&gt;
#         specified); use -c &amp;amp;lt;commit&amp;amp;gt; to reword the commit message&lt;br /&gt;
# u, update-ref &amp;amp;lt;ref&amp;amp;gt; = track a placeholder for the &amp;amp;lt;ref&amp;amp;gt; to be updated&lt;br /&gt;
#                       to this position in the new commits. The &amp;amp;lt;ref&amp;amp;gt; is&lt;br /&gt;
#                       updated at the end of the rebase&lt;br /&gt;
#&lt;br /&gt;
# These lines can be re-ordered; they are executed from top to bottom.&lt;br /&gt;
#&lt;br /&gt;
# If you remove a line here THAT COMMIT WILL BE LOST.&lt;br /&gt;
#&lt;br /&gt;
# However, if you remove everything, the rebase will be aborted.&lt;br /&gt;
#&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see all the commits which will be re-applied after the branch has been rolled back and commits from main been added.&lt;br /&gt;
&lt;br /&gt;
These all have the word &amp;lt;code&amp;gt;pick&amp;lt;/code&amp;gt; infront of them, meaning they will be committed as is, with the same message, and no editing happening.&lt;br /&gt;
&lt;br /&gt;
You can look over the other commands to see what you can do, but how it works is by replacing &amp;lt;code&amp;gt;pick&amp;lt;/code&amp;gt; with something else, e.g. &amp;lt;code&amp;gt;fixup&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;reword&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== The Fixup Commit ===&lt;br /&gt;
&lt;br /&gt;
This is a weird option when committing, that can be useful when you have an MR and you are wanting to keep a neat commit log, but are responding to review feedback.&lt;br /&gt;
&lt;br /&gt;
How this works, is lets say you’ve fixed something with a previous commit in your MR and were wanting to (when merging) squash this fix into that commit. But you want to have it as a separate commit to help the reviewer to see that you have fixed it.&lt;br /&gt;
&lt;br /&gt;
To do this you simply run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;git commit --fixup=&amp;quot;amend:&amp;lt;git_commit_id&amp;gt;&amp;quot;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Which will create a new commit with the message:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;amend! Add information for publicising events from BCSS and where to go&lt;br /&gt;
&lt;br /&gt;
&amp;amp;gt; Add information for publicising events from BCSS and where to go&amp;lt;/pre&amp;gt;&lt;br /&gt;
Which you can then push as its own commit.&lt;br /&gt;
&lt;br /&gt;
Then when you come to merge you can run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;git rebase -i main --autosquash&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Which will automatically move your amend commit to be &amp;lt;code&amp;gt;fixup&amp;lt;/code&amp;gt; above the commit you were amending.&lt;br /&gt;
&lt;br /&gt;
== Merging ==&lt;br /&gt;
&lt;br /&gt;
Normally merging is done via the interface on the remote repository system you are using. However it can be done in the command line as well (it can also be used in place of &amp;lt;code&amp;gt;rebase&amp;lt;/code&amp;gt; so you don’t have to use the dangerous &amp;lt;code&amp;gt;git push --force&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
It copies all the commits which have been added on a branch to the branch you are currently on (e.g. &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
So the process to merge a branch into main is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;git checkout main&lt;br /&gt;
git merge branch-name&lt;br /&gt;
git branch -d branch-name # Deletes the branch If you don&amp;#039;t need the branch any&lt;br /&gt;
                          # more&lt;br /&gt;
git push&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Conflicts can still happen, see [[#dealing-with-conflicts|above]] for more information about how to manage them.&lt;br /&gt;
&lt;br /&gt;
{{Note|text=&lt;br /&gt;
When merging, cherry-picking or other, and you are dealing with conflicts you need to use the subcommand with &amp;lt;code&amp;gt;--continue&amp;lt;/code&amp;gt;, for example &amp;lt;code&amp;gt;git merge --continue&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;git cherry-pick --continue&amp;lt;/code&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Cherry-picking ==&lt;br /&gt;
&lt;br /&gt;
Cherry picking allows you to bring a single commit (or multiple, see [[#more-on-commit-ids|here]]) from another branch to your current one.&lt;br /&gt;
&lt;br /&gt;
To do this, it is as simple as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;git cherry-pick commit-id&lt;br /&gt;
git push&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
== Submodules ==&lt;br /&gt;
&lt;br /&gt;
Submodules are normally used in what is called a “monorepo”, a repo which stores multiple difference projects or git repositories.&lt;br /&gt;
&lt;br /&gt;
It is also useful for refactoring some files. E.g. if you need the same files in multiple different projects (e.g. standardised tests or config files), it is common to add a “meta” repo which stores these projects, then add this as a submodule to each project which uses it.&lt;br /&gt;
&lt;br /&gt;
To add a submodule you can run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;git submodule add repo-url folder/to/store&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
This will clone the module inside the folder &amp;lt;code&amp;gt;folder/to/store&amp;lt;/code&amp;gt; and will add a &amp;lt;code&amp;gt;.gitmodule&amp;lt;/code&amp;gt; file in the base of the repo.&lt;br /&gt;
&lt;br /&gt;
When cloning the repo on other devices, you must remember to recursively clone all the submodules as well via:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;git clone --recurse-submodules -j8 project-url&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Note|text=&lt;br /&gt;
&amp;lt;code&amp;gt;-j8&amp;lt;/code&amp;gt; is an performance optimisation see [https://stackoverflow.com/questions/3796927/how-do-i-git-clone-a-repo-including-its-submodules#4438292 this Stack Overflow answer]&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Or if you have already cloned the repo and were wanting to update all the submodules, you can run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;git submodule update --init --recursive&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Managing submodules ===&lt;br /&gt;
&lt;br /&gt;
Once you have cloned a submodule, you will note that any time you pull the latest changes to it, you need to make another commit in the base repo with the update.&lt;br /&gt;
&lt;br /&gt;
This is so that the submodules are locked on specific commits until you specifically say “yes this next commit is fine”.&lt;br /&gt;
&lt;br /&gt;
== Extra Configuration ==&lt;br /&gt;
&lt;br /&gt;
Sometimes there are configuration options that git will recommend when they become a problem, for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;git config --global pull.rebase true&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
This means that when pulling from a branch which has new changes, it will rebase instead of merging the new commits.&lt;br /&gt;
&lt;br /&gt;
=== Commit Signing ===&lt;br /&gt;
&lt;br /&gt;
Commit signing is used to verify if you are who you say you are when committing (e.g. with your email address).&lt;br /&gt;
&lt;br /&gt;
I won’t go into much depth on this, instead just know it exists and is quite good practice to have but not necessary.&lt;br /&gt;
&lt;br /&gt;
You can read more [https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits here].&lt;br /&gt;
&lt;br /&gt;
Be aware that there are some consequences which come along with this:&lt;br /&gt;
&lt;br /&gt;
* If you have setup a strict mode with signing, you cannot commit if you loose access to your signing key&lt;br /&gt;
* When rebasing your changes, you have to resign all the commits (meaning you are the only one who can do it)&lt;/div&gt;</summary>
		<author><name>Hw2210</name></author>
	</entry>
</feed>