ok/jj
1
0
Fork 0
forked from mirrors/jj
jj/v0.10.0/tutorial/index.html
Ilya Grigoriev f67d6a192c docs SEO (direct website push): Use "latest" URL as canonical URL for older versions
The replacement was done by `sed`.

This should only change versions of the docs prior to 864869ab (in
particular, not the `latest` version nor the `prerelease` version), and
make it as though the old version of the docs were compiled with that
commit. It tries to solve the same problem:
https://www.google.com/search?q=jj+revsets still points to jj v0.13
docs.

Google seems really slow to update its index, and I'm beginning to worry
that it might think we have a spammy site with many almost identical
pages. I hope it will pick up this change once it tries to update its
crawl of pages it's already indexing.

Loosely related reading: https://news.ycombinator.com/item?id=40970987
2024-07-25 14:29:08 -07:00

1578 lines
No EOL
68 KiB
HTML

<!doctype html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="canonical" href="https://martinvonz.github.io/jj/latest/tutorial/">
<link rel="prev" href="../install-and-setup/">
<link rel="next" href="../github/">
<link rel="icon" href="../assets/images/favicon.png">
<meta name="generator" content="mkdocs-1.5.2, mkdocs-material-9.2.5">
<title>Tutorial and Birds-Eye View - Jujutsu docs</title>
<link rel="stylesheet" href="../assets/stylesheets/main.0e669242.min.css">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
<style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
<script>__md_scope=new URL("..",location),__md_hash=e=>[...e].reduce((e,_)=>(e<<5)-e+_.charCodeAt(0),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
</head>
<body dir="ltr">
<script>var palette=__md_get("__palette");if(palette&&"object"==typeof palette.color)for(var key of Object.keys(palette.color))document.body.setAttribute("data-md-color-"+key,palette.color[key])</script>
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
<label class="md-overlay" for="__drawer"></label>
<div data-md-component="skip">
<a href="#tutorial" class="md-skip">
Skip to content
</a>
</div>
<div data-md-component="announce">
</div>
<div data-md-color-scheme="default" data-md-component="outdated" hidden>
</div>
<header class="md-header md-header--shadow" data-md-component="header">
<nav class="md-header__inner md-grid" aria-label="Header">
<a href=".." title="Jujutsu docs" class="md-header__button md-logo" aria-label="Jujutsu docs" data-md-component="logo">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54Z"/></svg>
</a>
<label class="md-header__button md-icon" for="__drawer">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2Z"/></svg>
</label>
<div class="md-header__title" data-md-component="header-title">
<div class="md-header__ellipsis">
<div class="md-header__topic">
<span class="md-ellipsis">
Jujutsu docs
</span>
</div>
<div class="md-header__topic" data-md-component="header-topic">
<span class="md-ellipsis">
Tutorial and Birds-Eye View
</span>
</div>
</div>
</div>
<label class="md-header__button md-icon" for="__search">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg>
</label>
<div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label>
<div class="md-search__inner" role="search">
<form class="md-search__form" name="search">
<input type="text" class="md-search__input" name="query" aria-label="Search" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required>
<label class="md-search__icon md-icon" for="__search">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg>
</label>
<nav class="md-search__options" aria-label="Search">
<button type="reset" class="md-search__icon md-icon" title="Clear" aria-label="Clear" tabindex="-1">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41Z"/></svg>
</button>
</nav>
</form>
<div class="md-search__output">
<div class="md-search__scrollwrap" data-md-scrollfix>
<div class="md-search-result" data-md-component="search-result">
<div class="md-search-result__meta">
Initializing search
</div>
<ol class="md-search-result__list" role="presentation"></ol>
</div>
</div>
</div>
</div>
</div>
</nav>
</header>
<div class="md-container" data-md-component="container">
<main class="md-main" data-md-component="main">
<div class="md-main__inner md-grid">
<div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--primary" aria-label="Navigation" data-md-level="0">
<label class="md-nav__title" for="__drawer">
<a href=".." title="Jujutsu docs" class="md-nav__button md-logo" aria-label="Jujutsu docs" data-md-component="logo">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54Z"/></svg>
</a>
Jujutsu docs
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href=".." class="md-nav__link">
<span class="md-ellipsis">
Home
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--active md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_2" checked>
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
<span class="md-ellipsis">
Getting started
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_2_label" aria-expanded="true">
<label class="md-nav__title" for="__nav_2">
<span class="md-nav__icon md-icon"></span>
Getting started
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../install-and-setup/" class="md-nav__link">
<span class="md-ellipsis">
Installation and Setup
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--active">
<input class="md-nav__toggle md-toggle" type="checkbox" id="__toc">
<label class="md-nav__link md-nav__link--active" for="__toc">
<span class="md-ellipsis">
Tutorial and Birds-Eye View
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<a href="./" class="md-nav__link md-nav__link--active">
<span class="md-ellipsis">
Tutorial and Birds-Eye View
</span>
</a>
<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
Table of contents
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
<li class="md-nav__item">
<a href="#preparation" class="md-nav__link">
Preparation
</a>
</li>
<li class="md-nav__item">
<a href="#cloning-a-git-repo" class="md-nav__link">
Cloning a Git repo
</a>
</li>
<li class="md-nav__item">
<a href="#creating-our-first-change" class="md-nav__link">
Creating our first change
</a>
</li>
<li class="md-nav__item">
<a href="#the-log-command-and-revsets" class="md-nav__link">
The log command and "revsets"
</a>
</li>
<li class="md-nav__item">
<a href="#conflicts" class="md-nav__link">
Conflicts
</a>
</li>
<li class="md-nav__item">
<a href="#the-operation-log" class="md-nav__link">
The operation log
</a>
</li>
<li class="md-nav__item">
<a href="#moving-content-changes-between-commits" class="md-nav__link">
Moving content changes between commits
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../github/" class="md-nav__link">
<span class="md-ellipsis">
Working with GitHub
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../FAQ/" class="md-nav__link">
<span class="md-ellipsis">
FAQ
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_4" >
<label class="md-nav__link" for="__nav_4" id="__nav_4_label" tabindex="0">
<span class="md-ellipsis">
Concepts
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_4_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_4">
<span class="md-nav__icon md-icon"></span>
Concepts
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../working-copy/" class="md-nav__link">
<span class="md-ellipsis">
Working Copy
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../branches/" class="md-nav__link">
<span class="md-ellipsis">
Branches
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../conflicts/" class="md-nav__link">
<span class="md-ellipsis">
Conflicts
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../operation-log/" class="md-nav__link">
<span class="md-ellipsis">
Operation Log
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../glossary/" class="md-nav__link">
<span class="md-ellipsis">
Glossary
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_5" >
<label class="md-nav__link" for="__nav_5" id="__nav_5_label" tabindex="0">
<span class="md-ellipsis">
Configuration
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_5_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_5">
<span class="md-nav__icon md-icon"></span>
Configuration
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../config/" class="md-nav__link">
<span class="md-ellipsis">
Settings
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../revsets/" class="md-nav__link">
<span class="md-ellipsis">
Revset language
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../templates/" class="md-nav__link">
<span class="md-ellipsis">
Templating language
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_6" >
<label class="md-nav__link" for="__nav_6" id="__nav_6_label" tabindex="0">
<span class="md-ellipsis">
Comparisons
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_6_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_6">
<span class="md-nav__icon md-icon"></span>
Comparisons
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../git-comparison/" class="md-nav__link">
<span class="md-ellipsis">
Git comparison
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../git-compatibility/" class="md-nav__link">
<span class="md-ellipsis">
Git compatibility
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../sapling-comparison/" class="md-nav__link">
<span class="md-ellipsis">
Sapling
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../related-work/" class="md-nav__link">
<span class="md-ellipsis">
Other related work
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_7" >
<label class="md-nav__link" for="__nav_7" id="__nav_7_label" tabindex="0">
<span class="md-ellipsis">
Technical details
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_7_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_7">
<span class="md-nav__icon md-icon"></span>
Technical details
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../technical/architecture/" class="md-nav__link">
<span class="md-ellipsis">
Architecture
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../technical/concurrency/" class="md-nav__link">
<span class="md-ellipsis">
Concurrency
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../technical/conflicts/" class="md-nav__link">
<span class="md-ellipsis">
Conflicts
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_8" >
<label class="md-nav__link" for="__nav_8" id="__nav_8_label" tabindex="0">
<span class="md-ellipsis">
Contributing
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_8_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_8">
<span class="md-nav__icon md-icon"></span>
Contributing
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../contributing/" class="md-nav__link">
<span class="md-ellipsis">
Guidelines and "How to...?"
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../code-of-conduct/" class="md-nav__link">
<span class="md-ellipsis">
Code of conduct
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_9" >
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
<span class="md-ellipsis">
Design docs
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_9_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_9">
<span class="md-nav__icon md-icon"></span>
Design docs
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../design/git-submodules/" class="md-nav__link">
<span class="md-ellipsis">
git-submodules
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../design/git-submodule-storage/" class="md-nav__link">
<span class="md-ellipsis">
git-submodule-storage
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../design/run/" class="md-nav__link">
<span class="md-ellipsis">
JJ run
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../design/tracking-branches/" class="md-nav__link">
<span class="md-ellipsis">
Tracking branches
</span>
</a>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" >
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
Table of contents
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
<li class="md-nav__item">
<a href="#preparation" class="md-nav__link">
Preparation
</a>
</li>
<li class="md-nav__item">
<a href="#cloning-a-git-repo" class="md-nav__link">
Cloning a Git repo
</a>
</li>
<li class="md-nav__item">
<a href="#creating-our-first-change" class="md-nav__link">
Creating our first change
</a>
</li>
<li class="md-nav__item">
<a href="#the-log-command-and-revsets" class="md-nav__link">
The log command and "revsets"
</a>
</li>
<li class="md-nav__item">
<a href="#conflicts" class="md-nav__link">
Conflicts
</a>
</li>
<li class="md-nav__item">
<a href="#the-operation-log" class="md-nav__link">
The operation log
</a>
</li>
<li class="md-nav__item">
<a href="#moving-content-changes-between-commits" class="md-nav__link">
Moving content changes between commits
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-content" data-md-component="content">
<article class="md-content__inner md-typeset">
<h1 id="tutorial">Tutorial<a class="headerlink" href="#tutorial" title="Permanent link">&para;</a></h1>
<p>This text assumes that the reader is familiar with Git.</p>
<h2 id="preparation">Preparation<a class="headerlink" href="#preparation" title="Permanent link">&para;</a></h2>
<p>If you haven't already, make sure you
<a href="../install-and-setup/">install and configure Jujutsu</a>.</p>
<h2 id="cloning-a-git-repo">Cloning a Git repo<a class="headerlink" href="#cloning-a-git-repo" title="Permanent link">&para;</a></h2>
<p>Let's start by cloning GitHub's Hello-World repo using <code>jj</code>:
<div class="highlight"><pre><span></span><code><span class="c1"># Note the &quot;git&quot; before &quot;clone&quot; (there is no support for cloning native jj</span>
<span class="c1"># repos yet)</span>
$<span class="w"> </span>jj<span class="w"> </span>git<span class="w"> </span>clone<span class="w"> </span>https://github.com/octocat/Hello-World
Fetching<span class="w"> </span>into<span class="w"> </span>new<span class="w"> </span>repo<span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="s2">&quot;/tmp/tmp.O1DWMiaKd4/Hello-World&quot;</span>
Working<span class="w"> </span>copy<span class="w"> </span>now<span class="w"> </span>at:<span class="w"> </span>d7439b06fbef<span class="w"> </span><span class="o">(</span>no<span class="w"> </span>description<span class="w"> </span><span class="nb">set</span><span class="o">)</span>
Added<span class="w"> </span><span class="m">1</span><span class="w"> </span>files,<span class="w"> </span>modified<span class="w"> </span><span class="m">0</span><span class="w"> </span>files,<span class="w"> </span>removed<span class="w"> </span><span class="m">0</span><span class="w"> </span>files
$<span class="w"> </span><span class="nb">cd</span><span class="w"> </span>Hello-World
</code></pre></div></p>
<p>Running <code>jj st</code> (short for<code>jj status</code>) now yields something like this:
<div class="highlight"><pre><span></span><code>$<span class="w"> </span>jj<span class="w"> </span>st
Parent<span class="w"> </span>commit:<span class="w"> </span>7fd1a60b01f9<span class="w"> </span>Merge<span class="w"> </span>pull<span class="w"> </span>request<span class="w"> </span><span class="c1">#6 from Spaceghost/patch-1</span>
Working<span class="w"> </span>copy<span class="w"> </span>:<span class="w"> </span>d7439b06fbef<span class="w"> </span><span class="o">(</span>no<span class="w"> </span>description<span class="w"> </span><span class="nb">set</span><span class="o">)</span>
The<span class="w"> </span>working<span class="w"> </span>copy<span class="w"> </span>is<span class="w"> </span>clean
</code></pre></div></p>
<p>We can see from the output above that our working copy is a real commit with a
commit ID (<code>d7439b06fbef</code> in the example). When you make a change in the working
copy, the working-copy commit gets automatically amended by the next <code>jj</code>
command.</p>
<h2 id="creating-our-first-change">Creating our first change<a class="headerlink" href="#creating-our-first-change" title="Permanent link">&para;</a></h2>
<p>Now let's say we want to edit the <code>README</code> file in the repo to say "Goodbye"
instead of "Hello". Let's start by describing the change (adding a
commit message) so we don't forget what we're working on:
<div class="highlight"><pre><span></span><code><span class="c1"># This will bring up $EDITOR (or `pico` or `Notepad` by default). Enter</span>
<span class="c1"># something like &quot;Say goodbye&quot; in the editor and then save the file and close</span>
<span class="c1"># the editor.</span>
$<span class="w"> </span>jj<span class="w"> </span>describe
Working<span class="w"> </span>copy<span class="w"> </span>now<span class="w"> </span>at:<span class="w"> </span>e427edcfd0ba<span class="w"> </span>Say<span class="w"> </span>goodbye
</code></pre></div></p>
<p>Now make the change in the README:
<div class="highlight"><pre><span></span><code><span class="c1"># Adjust as necessary for compatibility with your flavor of `sed`</span>
$<span class="w"> </span>sed<span class="w"> </span>-i<span class="w"> </span><span class="s1">&#39;s/Hello/Goodbye/&#39;</span><span class="w"> </span>README
$<span class="w"> </span>jj<span class="w"> </span>st
Parent<span class="w"> </span>commit:<span class="w"> </span>7fd1a60b01f9<span class="w"> </span>Merge<span class="w"> </span>pull<span class="w"> </span>request<span class="w"> </span><span class="c1">#6 from Spaceghost/patch-1</span>
Working<span class="w"> </span>copy<span class="w"> </span>:<span class="w"> </span>5d39e19dac36<span class="w"> </span>Say<span class="w"> </span>goodbye
Working<span class="w"> </span>copy<span class="w"> </span>changes:
M<span class="w"> </span>README
</code></pre></div>
Note that you didn't have to tell Jujutsu to add the change like you would with
<code>git add</code>. You actually don't even need to tell it when you add new files or
remove existing files. To untrack a path, add it to your <code>.gitignore</code> and run
<code>jj untrack &lt;path&gt;</code>.</p>
<p>To see the diff, run <code>jj diff</code>:
<div class="highlight"><pre><span></span><code>$<span class="w"> </span>jj<span class="w"> </span>diff<span class="w"> </span>--git<span class="w"> </span><span class="c1"># Feel free to skip the `--git` flag</span>
diff<span class="w"> </span>--git<span class="w"> </span>a/README<span class="w"> </span>b/README
index<span class="w"> </span>980a0d5f19...1ce3f81130<span class="w"> </span><span class="m">100644</span>
---<span class="w"> </span>a/README
+++<span class="w"> </span>b/README
@@<span class="w"> </span>-1,1<span class="w"> </span>+1,1<span class="w"> </span>@@
-Hello<span class="w"> </span>World!
+Goodbye<span class="w"> </span>World!
</code></pre></div>
Jujutsu's diff format currently defaults to inline coloring of the diff (like
<code>git diff --color-words</code>), so we used <code>--git</code> above to make the diff readable in
this tutorial.</p>
<p>As you may have noticed, the working-copy commit's ID changed both when we
edited the description and when we edited the README. However, the parent commit
stayed the same. Each change to the working-copy commit amends the previous
version. So how do we tell Jujutsu that we are done amending the current change
and want to start working on a new one? That is what <code>jj new</code> is for. That will
create a new commit on top of your current working-copy commit. The new commit
is for the working-copy changes. For familiarity for user coming from other
VCSs, there is also a <code>jj checkout/co</code> command, which is practically a synonym
for <code>jj new</code> (you can specify a destination for <code>jj new</code> as well).</p>
<p>So, let's say we're now done with this change, so we create a new change:
<div class="highlight"><pre><span></span><code>$<span class="w"> </span>jj<span class="w"> </span>new
Working<span class="w"> </span>copy<span class="w"> </span>now<span class="w"> </span>at:<span class="w"> </span>aef4df99ea11<span class="w"> </span><span class="o">(</span>no<span class="w"> </span>description<span class="w"> </span><span class="nb">set</span><span class="o">)</span>
$<span class="w"> </span>jj<span class="w"> </span>st
Parent<span class="w"> </span>commit:<span class="w"> </span>5d39e19dac36<span class="w"> </span>Say<span class="w"> </span>goodbye
Working<span class="w"> </span>copy<span class="w"> </span>:<span class="w"> </span>aef4df99ea11<span class="w"> </span><span class="o">(</span>no<span class="w"> </span>description<span class="w"> </span><span class="nb">set</span><span class="o">)</span>
The<span class="w"> </span>working<span class="w"> </span>copy<span class="w"> </span>is<span class="w"> </span>clean
</code></pre></div></p>
<p>If we later realize that we want to make further changes, we can make them
in the working copy and then run <code>jj squash</code>. That command squashes the changes
from a given commit into its parent commit. Like most commands, it acts on the
working-copy commit by default. When run on the working-copy commit, it behaves
very similar to <code>git commit --amend</code>, and <code>jj amend</code> is in fact an alias for
<code>jj squash</code>.</p>
<p>Alternatively, we can use <code>jj edit &lt;commit&gt;</code> to resume editing a commit in the
working copy. Any further changes in the working copy will then amend the
commit. Whether you choose to checkout-and-squash or to edit typically depends
on how done you are with the change; if the change is almost done, it makes
sense to use <code>jj checkout</code> so you can easily review your adjustments with
<code>jj diff</code> before running <code>jj squash</code>. </p>
<h2 id="the-log-command-and-revsets">The log command and "revsets"<a class="headerlink" href="#the-log-command-and-revsets" title="Permanent link">&para;</a></h2>
<p>You're probably familiar with <code>git log</code>. Jujutsu has very similar functionality
in its <code>jj log</code> command:
<div class="highlight"><pre><span></span><code>$<span class="w"> </span>jj<span class="w"> </span>log
@<span class="w"> </span>mpqrykypylvy<span class="w"> </span>martinvonz@google.com<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">15</span>:00:22.000<span class="w"> </span>-08:00<span class="w"> </span>aef4df99ea11
<span class="w"> </span><span class="o">(</span>empty<span class="o">)</span><span class="w"> </span><span class="o">(</span>no<span class="w"> </span>description<span class="w"> </span><span class="nb">set</span><span class="o">)</span>
<span class="w"> </span>kntqzsqtnspv<span class="w"> </span>martinvonz@google.com<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">14</span>:56:59.000<span class="w"> </span>-08:00<span class="w"> </span>5d39e19dac36
<span class="w"> </span>Say<span class="w"> </span>goodbye
<span class="w"> </span>orrkosyozysx<span class="w"> </span>octocat@nowhere.com<span class="w"> </span><span class="m">2012</span>-03-06<span class="w"> </span><span class="m">15</span>:06:50.000<span class="w"> </span>-08:00<span class="w"> </span>master<span class="w"> </span>7fd1a60b01f9
<span class="w"> </span><span class="o">(</span>empty<span class="o">)</span><span class="w"> </span>Merge<span class="w"> </span>pull<span class="w"> </span>request<span class="w"> </span><span class="c1">#6 from Spaceghost/patch-1</span>
~
</code></pre></div></p>
<p>The <code>@</code> indicates the working-copy commit. The first ID on a line
(e.g. "mpqrykypylvy" above) is the "change ID", which is an ID that follows the
commit as it's rewritten (similar to Gerrit's Change-Id). The second ID is the
commit ID, which changes when you rewrite the commit. You can give either ID
to commands that take revisions as arguments. We will generally prefer change
IDs because they stay the same when the commit is rewritten.</p>
<p>By default, <code>jj log</code> lists your local commits, with some remote commits added
for context. The <code>~</code> indicates that the commit has parents that are not
included in the graph. We can use the <code>-r</code> flag to select a different set of
revisions to list. The flag accepts a <a href="../revsets/">"revset"</a>, which is an
expression in a simple language for specifying revisions. For example, <code>@</code>
refers to the working-copy commit, <code>root()</code> refers to the root commit,
<code>branches()</code> refers to all commits pointed to by branches. We can combine
expressions with <code>|</code> for union, <code>&amp;</code> for intersection and <code>~</code> for difference. For
example:
<div class="highlight"><pre><span></span><code>$<span class="w"> </span>jj<span class="w"> </span>log<span class="w"> </span>-r<span class="w"> </span><span class="s1">&#39;@ | root() | branches()&#39;</span>
@<span class="w"> </span>mpqrykypylvy<span class="w"> </span>martinvonz@google.com<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">15</span>:00:22.000<span class="w"> </span>-08:00<span class="w"> </span>aef4df99ea11
<span class="w"> </span><span class="o">(</span>empty<span class="o">)</span><span class="w"> </span><span class="o">(</span>no<span class="w"> </span>description<span class="w"> </span><span class="nb">set</span><span class="o">)</span>
<span class="w"> </span><span class="w"> </span>kowxouwzwxmv<span class="w"> </span>octocat@nowhere.com<span class="w"> </span><span class="m">2014</span>-06-10<span class="w"> </span><span class="m">15</span>:22:26.000<span class="w"> </span>-07:00<span class="w"> </span><span class="nb">test</span><span class="w"> </span>b3cbd5bbd7e8
╭─╯<span class="w"> </span>Create<span class="w"> </span>CONTRIBUTING.md
<span class="w"> </span><span class="w"> </span>tpstlustrvsn<span class="w"> </span>support+octocat@github.com<span class="w"> </span><span class="m">2018</span>-05-10<span class="w"> </span><span class="m">12</span>:55:19.000<span class="w"> </span>-05:00<span class="w"> </span>octocat-patch-1<span class="w"> </span>b1b3f9723831
├─╯<span class="w"> </span>sentence<span class="w"> </span><span class="k">case</span>
<span class="w"> </span>orrkosyozysx<span class="w"> </span>octocat@nowhere.com<span class="w"> </span><span class="m">2012</span>-03-06<span class="w"> </span><span class="m">15</span>:06:50.000<span class="w"> </span>-08:00<span class="w"> </span>master<span class="w"> </span>7fd1a60b01f9
<span class="w"> </span><span class="o">(</span>empty<span class="o">)</span><span class="w"> </span>Merge<span class="w"> </span>pull<span class="w"> </span>request<span class="w"> </span><span class="c1">#6 from Spaceghost/patch-1</span>
<span class="w"> </span>zzzzzzzzzzzz<span class="w"> </span><span class="m">1970</span>-01-01<span class="w"> </span><span class="m">00</span>:00:00.000<span class="w"> </span>+00:00<span class="w"> </span><span class="m">000000000000</span>
<span class="w"> </span><span class="o">(</span>empty<span class="o">)</span><span class="w"> </span><span class="o">(</span>no<span class="w"> </span>description<span class="w"> </span><span class="nb">set</span><span class="o">)</span>
</code></pre></div></p>
<p>The <code>000000000000</code> commit (change ID <code>zzzzzzzzzzzz</code>) is a virtual commit that's
called the "root commit". It's the root commit of every repo. The <code>root()</code>
function in the revset matches it.</p>
<p>There are also operators for getting the parents (<code>foo-</code>), children (<code>foo+</code>),
ancestors (<code>::foo</code>), descendants (<code>foo::</code>), DAG range (<code>foo::bar</code>, like
<code>git log --ancestry-path</code>), range (<code>foo..bar</code>, same as Git's). There are also a
few more functions, such as <code>heads(&lt;set&gt;)</code>, which filters out revisions in the
input set if they're ancestors of other revisions in the set.</p>
<h2 id="conflicts">Conflicts<a class="headerlink" href="#conflicts" title="Permanent link">&para;</a></h2>
<p>Now let's see how Jujutsu deals with merge conflicts. We'll start by making some
commits:
<div class="highlight"><pre><span></span><code><span class="c1"># Start creating a chain of commits off of the `master` branch</span>
$<span class="w"> </span>jj<span class="w"> </span>new<span class="w"> </span>master<span class="w"> </span>-m<span class="w"> </span>A<span class="p">;</span><span class="w"> </span><span class="nb">echo</span><span class="w"> </span>a<span class="w"> </span>&gt;<span class="w"> </span>file1
Working<span class="w"> </span>copy<span class="w"> </span>now<span class="w"> </span>at:<span class="w"> </span>00a2aeed556a<span class="w"> </span>A
Added<span class="w"> </span><span class="m">0</span><span class="w"> </span>files,<span class="w"> </span>modified<span class="w"> </span><span class="m">1</span><span class="w"> </span>files,<span class="w"> </span>removed<span class="w"> </span><span class="m">0</span><span class="w"> </span>files
$<span class="w"> </span>jj<span class="w"> </span>new<span class="w"> </span>-m<span class="w"> </span>B1<span class="p">;</span><span class="w"> </span><span class="nb">echo</span><span class="w"> </span>b1<span class="w"> </span>&gt;<span class="w"> </span>file1
Working<span class="w"> </span>copy<span class="w"> </span>now<span class="w"> </span>at:<span class="w"> </span>967d9f9fd288<span class="w"> </span>B1
$<span class="w"> </span>jj<span class="w"> </span>new<span class="w"> </span>-m<span class="w"> </span>B2<span class="p">;</span><span class="w"> </span><span class="nb">echo</span><span class="w"> </span>b2<span class="w"> </span>&gt;<span class="w"> </span>file1
Working<span class="w"> </span>copy<span class="w"> </span>now<span class="w"> </span>at:<span class="w"> </span>8ebeaffa332b<span class="w"> </span>B2
$<span class="w"> </span>jj<span class="w"> </span>new<span class="w"> </span>-m<span class="w"> </span>C<span class="p">;</span><span class="w"> </span><span class="nb">echo</span><span class="w"> </span>c<span class="w"> </span>&gt;<span class="w"> </span>file2
Working<span class="w"> </span>copy<span class="w"> </span>now<span class="w"> </span>at:<span class="w"> </span>62a3c6d315cd<span class="w"> </span>C
$<span class="w"> </span>jj<span class="w"> </span>log
@<span class="w"> </span>qzvqqupxlkot<span class="w"> </span>martinvonz@google.com<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">15</span>:07:41.946<span class="w"> </span>-08:00<span class="w"> </span>2370ddf3fa39
<span class="w"> </span>C
<span class="w"> </span>puqltuttrvzp<span class="w"> </span>martinvonz@google.com<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">15</span>:07:33.000<span class="w"> </span>-08:00<span class="w"> </span>daa6ffd5a09a
<span class="w"> </span>B2
<span class="w"> </span>ovknlmrokpkl<span class="w"> </span>martinvonz@google.com<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">15</span>:07:24.000<span class="w"> </span>-08:00<span class="w"> </span>7d7c6e6bd0b4
<span class="w"> </span>B1
<span class="w"> </span>nuvyytnqlquo<span class="w"> </span>martinvonz@google.com<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">15</span>:07:05.000<span class="w"> </span>-08:00<span class="w"> </span>5dda2f097aa9
<span class="w"> </span>A
<span class="w"> </span><span class="w"> </span>kntqzsqtnspv<span class="w"> </span>martinvonz@google.com<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">14</span>:56:59.000<span class="w"> </span>-08:00<span class="w"> </span>5d39e19dac36
├─╯<span class="w"> </span>Say<span class="w"> </span>goodbye
<span class="w"> </span>orrkosyozysx<span class="w"> </span>octocat@nowhere.com<span class="w"> </span><span class="m">2012</span>-03-06<span class="w"> </span><span class="m">15</span>:06:50.000<span class="w"> </span>-08:00<span class="w"> </span>master<span class="w"> </span>7fd1a60b01f9
<span class="w"> </span><span class="o">(</span>empty<span class="o">)</span><span class="w"> </span>Merge<span class="w"> </span>pull<span class="w"> </span>request<span class="w"> </span><span class="c1">#6 from Spaceghost/patch-1</span>
~
</code></pre></div></p>
<p>We now have a few commits, where A, B1, and B2 modify the same file, while C
modifies a different file. Let's now rebase B2 directly onto A:
<div class="highlight"><pre><span></span><code>$<span class="w"> </span>jj<span class="w"> </span>rebase<span class="w"> </span>-s<span class="w"> </span>puqltuttrvzp<span class="w"> </span>-d<span class="w"> </span>nuvyytnqlquo
Rebased<span class="w"> </span><span class="m">2</span><span class="w"> </span>commits
Working<span class="w"> </span>copy<span class="w"> </span>now<span class="w"> </span>at:<span class="w"> </span>1978b53430cd<span class="w"> </span>C
Added<span class="w"> </span><span class="m">0</span><span class="w"> </span>files,<span class="w"> </span>modified<span class="w"> </span><span class="m">1</span><span class="w"> </span>files,<span class="w"> </span>removed<span class="w"> </span><span class="m">0</span><span class="w"> </span>files
$<span class="w"> </span>jj<span class="w"> </span>log
@<span class="w"> </span>qzvqqupxlkot<span class="w"> </span>martinvonz@google.com<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">15</span>:08:33.000<span class="w"> </span>-08:00<span class="w"> </span>1978b53430cd<span class="w"> </span>conflict
<span class="w"> </span>C
<span class="w"> </span>puqltuttrvzp<span class="w"> </span>martinvonz@google.com<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">15</span>:08:33.000<span class="w"> </span>-08:00<span class="w"> </span>f7fb5943ee41<span class="w"> </span>conflict
<span class="w"> </span>B2
<span class="w"> </span><span class="w"> </span>ovknlmrokpkl<span class="w"> </span>martinvonz@google.com<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">15</span>:07:24.000<span class="w"> </span>-08:00<span class="w"> </span>7d7c6e6bd0b4
├─╯<span class="w"> </span>B1
<span class="w"> </span>nuvyytnqlquo<span class="w"> </span>martinvonz@google.com<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">15</span>:07:05.000<span class="w"> </span>-08:00<span class="w"> </span>5dda2f097aa9
<span class="w"> </span>A
<span class="w"> </span><span class="w"> </span>kntqzsqtnspv<span class="w"> </span>martinvonz@google.com<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">14</span>:56:59.000<span class="w"> </span>-08:00<span class="w"> </span>5d39e19dac36
├─╯<span class="w"> </span>Say<span class="w"> </span>goodbye
<span class="w"> </span>orrkosyozysx<span class="w"> </span>octocat@nowhere.com<span class="w"> </span><span class="m">2012</span>-03-06<span class="w"> </span><span class="m">15</span>:06:50.000<span class="w"> </span>-08:00<span class="w"> </span>master<span class="w"> </span>7fd1a60b01f9
<span class="w"> </span><span class="o">(</span>empty<span class="o">)</span><span class="w"> </span>Merge<span class="w"> </span>pull<span class="w"> </span>request<span class="w"> </span><span class="c1">#6 from Spaceghost/patch-1</span>
~
</code></pre></div></p>
<p>There are several things worth noting here. First, the <code>jj rebase</code> command said
"Rebased 2 commits". That's because we asked it to rebase commit B2 with the
<code>-s</code> option, which also rebases descendants (commit C in this case). Second,
because B2 modified the same file (and word) as B1, rebasing
it resulted in conflicts, as the <code>jj log</code> output indicates. Third, the conflicts
did not prevent the rebase from completing successfully, nor did it prevent C
from getting rebased on top.</p>
<p>Now let's resolve the conflict in B2. We'll do that by creating a new commit on
top of B2. Once we've resolved the conflict, we'll squash the conflict
resolution into the conflicted B2. That might look like this:
<div class="highlight"><pre><span></span><code>$<span class="w"> </span>jj<span class="w"> </span>new<span class="w"> </span>puqltuttrvzp<span class="w"> </span><span class="c1"># Replace the ID by what you have for B2</span>
Working<span class="w"> </span>copy<span class="w"> </span>now<span class="w"> </span>at:<span class="w"> </span>c7068d1c23fd<span class="w"> </span><span class="o">(</span>no<span class="w"> </span>description<span class="w"> </span><span class="nb">set</span><span class="o">)</span>
Added<span class="w"> </span><span class="m">0</span><span class="w"> </span>files,<span class="w"> </span>modified<span class="w"> </span><span class="m">0</span><span class="w"> </span>files,<span class="w"> </span>removed<span class="w"> </span><span class="m">1</span><span class="w"> </span>files
$<span class="w"> </span>jj<span class="w"> </span>st
Parent<span class="w"> </span>commit:<span class="w"> </span>f7fb5943ee41<span class="w"> </span>B2
Working<span class="w"> </span>copy<span class="w"> </span>:<span class="w"> </span>c7068d1c23fd<span class="w"> </span><span class="o">(</span>no<span class="w"> </span>description<span class="w"> </span><span class="nb">set</span><span class="o">)</span>
The<span class="w"> </span>working<span class="w"> </span>copy<span class="w"> </span>is<span class="w"> </span>clean
There<span class="w"> </span>are<span class="w"> </span>unresolved<span class="w"> </span>conflicts<span class="w"> </span>at<span class="w"> </span>these<span class="w"> </span>paths:
file1<span class="w"> </span><span class="m">2</span>-sided<span class="w"> </span>conflict
$<span class="w"> </span>cat<span class="w"> </span>file1
<span class="o">&lt;&lt;&lt;&lt;&lt;&lt;</span>&lt;
%%%%%%%
-b1
+a
+++++++
b2
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
$<span class="w"> </span><span class="nb">echo</span><span class="w"> </span>resolved<span class="w"> </span>&gt;<span class="w"> </span>file1
$<span class="w"> </span>jj<span class="w"> </span>squash
Rebased<span class="w"> </span><span class="m">1</span><span class="w"> </span>descendant<span class="w"> </span>commits
Working<span class="w"> </span>copy<span class="w"> </span>now<span class="w"> </span>at:<span class="w"> </span>e3c279cc2043<span class="w"> </span><span class="o">(</span>no<span class="w"> </span>description<span class="w"> </span><span class="nb">set</span><span class="o">)</span>
$<span class="w"> </span>jj<span class="w"> </span>log
@<span class="w"> </span>ntxxqymrlvxu<span class="w"> </span>martinvonz@google.com<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">19</span>:34:09.000<span class="w"> </span>-08:00<span class="w"> </span>e3c279cc2043
<span class="w"> </span><span class="o">(</span>empty<span class="o">)</span><span class="w"> </span><span class="o">(</span>no<span class="w"> </span>description<span class="w"> </span><span class="nb">set</span><span class="o">)</span>
<span class="w"> </span><span class="w"> </span>qzvqqupxlkot<span class="w"> </span>martinvonz@google.com<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">19</span>:34:09.000<span class="w"> </span>-08:00<span class="w"> </span>b9da9d28b26b
├─╯<span class="w"> </span>C
<span class="w"> </span>puqltuttrvzp<span class="w"> </span>martinvonz@google.com<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">19</span>:34:09.000<span class="w"> </span>-08:00<span class="w"> </span>2c7a658e2586
<span class="w"> </span>B2
<span class="w"> </span><span class="w"> </span>ovknlmrokpkl<span class="w"> </span>martinvonz@google.com<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">15</span>:07:24.000<span class="w"> </span>-08:00<span class="w"> </span>7d7c6e6bd0b4
├─╯<span class="w"> </span>B1
<span class="w"> </span>nuvyytnqlquo<span class="w"> </span>martinvonz@google.com<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">15</span>:07:05.000<span class="w"> </span>-08:00<span class="w"> </span>5dda2f097aa9
<span class="w"> </span>A
<span class="w"> </span><span class="w"> </span>kntqzsqtnspv<span class="w"> </span>martinvonz@google.com<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">14</span>:56:59.000<span class="w"> </span>-08:00<span class="w"> </span>5d39e19dac36
├─╯<span class="w"> </span>Say<span class="w"> </span>goodbye
<span class="w"> </span>orrkosyozysx<span class="w"> </span>octocat@nowhere.com<span class="w"> </span><span class="m">2012</span>-03-06<span class="w"> </span><span class="m">15</span>:06:50.000<span class="w"> </span>-08:00<span class="w"> </span>master<span class="w"> </span>7fd1a60b01f9
<span class="w"> </span><span class="o">(</span>empty<span class="o">)</span><span class="w"> </span>Merge<span class="w"> </span>pull<span class="w"> </span>request<span class="w"> </span><span class="c1">#6 from Spaceghost/patch-1</span>
~
</code></pre></div></p>
<p>Note that commit C automatically got rebased on top of the resolved B2, and that
C is also resolved (since it modified only a different file).</p>
<p>By the way, if we want to get rid of B1 now, we can run <code>jj abandon
ovknlmrokpkl</code>. That will hide the commit from the log output and will rebase any
descendants to its parent.</p>
<h2 id="the-operation-log">The operation log<a class="headerlink" href="#the-operation-log" title="Permanent link">&para;</a></h2>
<p>Jujutsu keeps a record of all changes you've made to the repo in what's called
the "operation log". Use the <code>jj op</code> (short for <code>jj operation</code>) family of
commands to interact with it. To list the operations, use <code>jj op log</code>:
<div class="highlight"><pre><span></span><code>$<span class="w"> </span>jj<span class="w"> </span>op<span class="w"> </span>log
@<span class="w"> </span>d3b77addea49<span class="w"> </span>martinvonz@vonz.svl.corp.google.com<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">19</span>:34:09.549<span class="w"> </span>-08:00<span class="w"> </span>-<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">19</span>:34:09.552<span class="w"> </span>-08:00
<span class="w"> </span>squash<span class="w"> </span>commit<span class="w"> </span>63874fe6c4fba405ffc38b0dd926f03b715cf7ef
<span class="w"> </span>args:<span class="w"> </span>jj<span class="w"> </span>squash
<span class="w"> </span>6fc1873c1180<span class="w"> </span>martinvonz@vonz.svl.corp.google.com<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">19</span>:34:09.548<span class="w"> </span>-08:00<span class="w"> </span>-<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">19</span>:34:09.549<span class="w"> </span>-08:00
<span class="w"> </span>snapshot<span class="w"> </span>working<span class="w"> </span>copy
<span class="w"> </span>ed91f7bcc1fb<span class="w"> </span>martinvonz@vonz.svl.corp.google.com<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">19</span>:32:46.007<span class="w"> </span>-08:00<span class="w"> </span>-<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">19</span>:32:46.008<span class="w"> </span>-08:00
<span class="w"> </span>new<span class="w"> </span>empty<span class="w"> </span>commit
<span class="w"> </span>args:<span class="w"> </span>jj<span class="w"> </span>new<span class="w"> </span>puqltuttrvzp
<span class="w"> </span>367400773f87<span class="w"> </span>martinvonz@vonz.svl.corp.google.com<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">15</span>:08:33.917<span class="w"> </span>-08:00<span class="w"> </span>-<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">15</span>:08:33.920<span class="w"> </span>-08:00
<span class="w"> </span>rebase<span class="w"> </span>commit<span class="w"> </span>daa6ffd5a09a8a7d09a65796194e69b7ed0a566d<span class="w"> </span>and<span class="w"> </span>descendants
<span class="w"> </span>args:<span class="w"> </span>jj<span class="w"> </span>rebase<span class="w"> </span>-s<span class="w"> </span>puqltuttrvzp<span class="w"> </span>-d<span class="w"> </span>nuvyytnqlquo
<span class="o">[</span>many<span class="w"> </span>more<span class="w"> </span>lines<span class="o">]</span>
</code></pre></div></p>
<p>The most useful command is <code>jj undo</code> (alias for <code>jj op undo</code>), which will undo
an operation. By default, it will undo the most recent operation. Let's try it:
<div class="highlight"><pre><span></span><code>$<span class="w"> </span>jj<span class="w"> </span>undo
Working<span class="w"> </span>copy<span class="w"> </span>now<span class="w"> </span>at:<span class="w"> </span>63874fe6c4fb<span class="w"> </span><span class="o">(</span>no<span class="w"> </span>description<span class="w"> </span><span class="nb">set</span><span class="o">)</span>
$<span class="w"> </span>jj<span class="w"> </span>log
@<span class="w"> </span>zxoosnnpvvpn<span class="w"> </span>martinvonz@google.com<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">19</span>:34:09.000<span class="w"> </span>-08:00<span class="w"> </span>63874fe6c4fb
<span class="w"> </span><span class="o">(</span>no<span class="w"> </span>description<span class="w"> </span><span class="nb">set</span><span class="o">)</span>
<span class="w"> </span><span class="w"> </span>qzvqqupxlkot<span class="w"> </span>martinvonz@google.com<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">15</span>:08:33.000<span class="w"> </span>-08:00<span class="w"> </span>1978b53430cd<span class="w"> </span>conflict
├─╯<span class="w"> </span>C
<span class="w"> </span>puqltuttrvzp<span class="w"> </span>martinvonz@google.com<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">15</span>:08:33.000<span class="w"> </span>-08:00<span class="w"> </span>f7fb5943ee41<span class="w"> </span>conflict
<span class="w"> </span>B2
<span class="w"> </span><span class="w"> </span>ovknlmrokpkl<span class="w"> </span>martinvonz@google.com<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">15</span>:07:24.000<span class="w"> </span>-08:00<span class="w"> </span>7d7c6e6bd0b4
├─╯<span class="w"> </span>B1
<span class="w"> </span>nuvyytnqlquo<span class="w"> </span>martinvonz@google.com<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">15</span>:07:05.000<span class="w"> </span>-08:00<span class="w"> </span>5dda2f097aa9
<span class="w"> </span>A
<span class="w"> </span><span class="w"> </span>kntqzsqtnspv<span class="w"> </span>martinvonz@google.com<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">14</span>:56:59.000<span class="w"> </span>-08:00<span class="w"> </span>5d39e19dac36
├─╯<span class="w"> </span>Say<span class="w"> </span>goodbye
<span class="w"> </span>orrkosyozysx<span class="w"> </span>octocat@nowhere.com<span class="w"> </span><span class="m">2012</span>-03-06<span class="w"> </span><span class="m">15</span>:06:50.000<span class="w"> </span>-08:00<span class="w"> </span>master<span class="w"> </span>7fd1a60b01f9
<span class="w"> </span><span class="o">(</span>empty<span class="o">)</span><span class="w"> </span>Merge<span class="w"> </span>pull<span class="w"> </span>request<span class="w"> </span><span class="c1">#6 from Spaceghost/patch-1</span>
~
</code></pre></div>
As you can perhaps see, that undid the <code>jj squash</code> invocation we used for
squashing the conflict resolution into commit B2 earlier. Notice that it also
updated the working copy.</p>
<p>You can also view the repo the way it looked after some earlier operation. For
example, if you want to see <code>jj log</code> output right after the <code>jj rebase</code> operation,
try <code>jj log --at-op=367400773f87</code> but use the hash from your own <code>jj op log</code>.</p>
<h2 id="moving-content-changes-between-commits">Moving content changes between commits<a class="headerlink" href="#moving-content-changes-between-commits" title="Permanent link">&para;</a></h2>
<p>You have already seen how <code>jj squash</code> can combine the changes from two commits
into one. There are several other commands for changing the contents of existing
commits. These commands assume that you have <code>meld</code> installed. If you prefer a
terminal-based diff editor, you
can <a href="../config/#setting-up-scm-diff-editor">configure <code>scm-diff-editor</code></a> instead.</p>
<p>We'll need some more complex content to test these commands, so let's create a
few more commits:
<div class="highlight"><pre><span></span><code>$<span class="w"> </span>jj<span class="w"> </span>new<span class="w"> </span>master<span class="w"> </span>-m<span class="w"> </span>abc<span class="p">;</span><span class="w"> </span><span class="nb">printf</span><span class="w"> </span><span class="s1">&#39;a\nb\nc\n&#39;</span><span class="w"> </span>&gt;<span class="w"> </span>file
Working<span class="w"> </span>copy<span class="w"> </span>now<span class="w"> </span>at:<span class="w"> </span>f94e49cf2547<span class="w"> </span>abc
Added<span class="w"> </span><span class="m">0</span><span class="w"> </span>files,<span class="w"> </span>modified<span class="w"> </span><span class="m">0</span><span class="w"> </span>files,<span class="w"> </span>removed<span class="w"> </span><span class="m">1</span><span class="w"> </span>files
$<span class="w"> </span>jj<span class="w"> </span>new<span class="w"> </span>-m<span class="w"> </span>ABC<span class="p">;</span><span class="w"> </span><span class="nb">printf</span><span class="w"> </span><span class="s1">&#39;A\nB\nc\n&#39;</span><span class="w"> </span>&gt;<span class="w"> </span>file
Working<span class="w"> </span>copy<span class="w"> </span>now<span class="w"> </span>at:<span class="w"> </span>6f30cd1fb351<span class="w"> </span>ABC
$<span class="w"> </span>jj<span class="w"> </span>new<span class="w"> </span>-m<span class="w"> </span>ABCD<span class="p">;</span><span class="w"> </span><span class="nb">printf</span><span class="w"> </span><span class="s1">&#39;A\nB\nC\nD\n&#39;</span><span class="w"> </span>&gt;<span class="w"> </span>file
Working<span class="w"> </span>copy<span class="w"> </span>now<span class="w"> </span>at:<span class="w"> </span>a67491542e10<span class="w"> </span>ABCD
$<span class="w"> </span>jj<span class="w"> </span>log<span class="w"> </span>-r<span class="w"> </span>master::@
@<span class="w"> </span>mrxqplykzpkw<span class="w"> </span>martinvonz@google.com<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">19</span>:38:21.000<span class="w"> </span>-08:00<span class="w"> </span>b98c607bf87f
<span class="w"> </span>ABCD
<span class="w"> </span>kwtuwqnmqyqp<span class="w"> </span>martinvonz@google.com<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">19</span>:38:12.000<span class="w"> </span>-08:00<span class="w"> </span>30aecc0871ea
<span class="w"> </span>ABC
<span class="w"> </span>ztqrpvnwqqnq<span class="w"> </span>martinvonz@google.com<span class="w"> </span><span class="m">2023</span>-02-12<span class="w"> </span><span class="m">19</span>:38:03.000<span class="w"> </span>-08:00<span class="w"> </span><span class="m">510022615871</span>
<span class="w"> </span>abc
<span class="w"> </span>orrkosyozysx<span class="w"> </span>octocat@nowhere.com<span class="w"> </span><span class="m">2012</span>-03-06<span class="w"> </span><span class="m">15</span>:06:50.000<span class="w"> </span>-08:00<span class="w"> </span>master<span class="w"> </span>7fd1a60b01f9
<span class="w"> </span><span class="o">(</span>empty<span class="o">)</span><span class="w"> </span>Merge<span class="w"> </span>pull<span class="w"> </span>request<span class="w"> </span><span class="c1">#6 from Spaceghost/patch-1</span>
~
</code></pre></div></p>
<p>We "forgot" to capitalize "c" in the second commit when we capitalized the other
letters. We then fixed that in the third commit when we also added "D". It would
be cleaner to move the capitalization of "c" into the second commit. We can do
that by running <code>jj squash -i</code> (short for <code>jj squash --interactive</code>) on the
third commit. Remember that <code>jj squash</code> moves all the changes from one commit
into its parent. <code>jj squash -i</code> moves only part of the changes into its parent.
Now try that:
<div class="highlight"><pre><span></span><code>$<span class="w"> </span>jj<span class="w"> </span>squash<span class="w"> </span>-i
Using<span class="w"> </span>default<span class="w"> </span>editor<span class="w"> </span><span class="s1">&#39;meld&#39;</span><span class="p">;</span><span class="w"> </span>you<span class="w"> </span>can<span class="w"> </span>change<span class="w"> </span>this<span class="w"> </span>by<span class="w"> </span>setting<span class="w"> </span>ui.diff-editor
Working<span class="w"> </span>copy<span class="w"> </span>now<span class="w"> </span>at:<span class="w"> </span>52a6c7fda1e3<span class="w"> </span>ABCD
</code></pre></div>
That will bring up Meld with a diff of the changes in the "ABCD" commit. Modify
the right side of the diff to have the desired end state in "ABC" by removing
the "D" line. Then save the changes and close Meld. If we look at the diff of
the second commit, we now see that all three lines got capitalized:
<div class="highlight"><pre><span></span><code>$<span class="w"> </span>jj<span class="w"> </span>diff<span class="w"> </span>-r<span class="w"> </span>@-
Modified<span class="w"> </span>regular<span class="w"> </span>file<span class="w"> </span>file:
<span class="w"> </span><span class="m">1</span><span class="w"> </span><span class="m">1</span>:<span class="w"> </span>aA
<span class="w"> </span><span class="m">2</span><span class="w"> </span><span class="m">2</span>:<span class="w"> </span>bB
<span class="w"> </span><span class="m">3</span><span class="w"> </span><span class="m">3</span>:<span class="w"> </span>cC
</code></pre></div></p>
<p>The child change ("ABCD" in our case) will have the same content <em>state</em> after
the <code>jj squash</code> command. That means that you can move any changes you want into
the parent change, even if they touch the same word, and it won't cause any
conflicts.</p>
<p>Let's try one final command for changing the contents of an exiting commit. That
command is <code>jj diffedit</code>, which lets you edit the contents of a commit without
checking it out.
<div class="highlight"><pre><span></span><code>$<span class="w"> </span>jj<span class="w"> </span>diffedit<span class="w"> </span>-r<span class="w"> </span>@-
Using<span class="w"> </span>default<span class="w"> </span>editor<span class="w"> </span><span class="s1">&#39;meld&#39;</span><span class="p">;</span><span class="w"> </span>you<span class="w"> </span>can<span class="w"> </span>change<span class="w"> </span>this<span class="w"> </span>by<span class="w"> </span>setting<span class="w"> </span>ui.diff-editor
Created<span class="w"> </span>70985eaa924f<span class="w"> </span>ABC
Rebased<span class="w"> </span><span class="m">1</span><span class="w"> </span>descendant<span class="w"> </span>commits
Working<span class="w"> </span>copy<span class="w"> </span>now<span class="w"> </span>at:<span class="w"> </span>1c72cd50525d<span class="w"> </span>ABCD
Added<span class="w"> </span><span class="m">0</span><span class="w"> </span>files,<span class="w"> </span>modified<span class="w"> </span><span class="m">1</span><span class="w"> </span>files,<span class="w"> </span>removed<span class="w"> </span><span class="m">0</span><span class="w"> </span>files
</code></pre></div>
When Meld starts, edit the right side by e.g. adding something to the first
line. Then save the changes and close Meld. You can now inspect the rewritten
commit with <code>jj diff -r @-</code> again and you should see your addition to the first
line. Unlike <code>jj squash -i</code>, which left the content state of the commit
unchanged, <code>jj diffedit</code> (typically) results in a different state, which means
that descendant commits may have conflicts.</p>
<p>Other commands for rewriting contents of existing commits are <code>jj split</code>, <code>jj
unsquash -i</code> and <code>jj move -i</code>. Now that you've seen how <code>jj squash -i</code> and <code>jj
diffedit</code> work, you can hopefully figure out how those work (with the help of
the instructions in the diff).</p>
</article>
</div>
</div>
</main>
<footer class="md-footer">
<div class="md-footer-meta md-typeset">
<div class="md-footer-meta__inner md-grid">
<div class="md-copyright">
Made with
<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
Material for MkDocs
</a>
</div>
</div>
</div>
</footer>
</div>
<div class="md-dialog" data-md-component="dialog">
<div class="md-dialog__inner md-typeset"></div>
</div>
<script id="__config" type="application/json">{"base": "..", "features": [], "search": "../assets/javascripts/workers/search.dfff1995.min.js", "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version": "Select version"}, "version": {"provider": "mike"}}</script>
<script src="../assets/javascripts/bundle.78eede0e.min.js"></script>
</body>
</html>