Last active
April 8, 2023 17:26
-
-
Save jaraco/85bdc8454886dee18d26a3486f6c9ae3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat >> $HGRCPATH <<EOF | |
> [phases] | |
> publish = False | |
> [alias] | |
> qlog = log --template='{rev} - {node|short} {desc} ({phase})\n' | |
> [diff] | |
> git = 1 | |
> unified = 0 | |
> [extensions] | |
> EOF | |
$ echo "evolve=$(echo $(dirname $TESTDIR))/hgext3rd/evolve/" >> $HGRCPATH | |
$ mkcommit() { | |
> echo "$1" > "$1" | |
> hg add "$1" | |
> hg ci -m "add $1" | |
> } | |
$ mkstack() { | |
> # Creates a stack of commit based on $1 with messages from $2, $3 .. | |
> hg update $1 -C | |
> shift | |
> mkcommits $* | |
> } | |
$ glog() { | |
> hg log -G --template '{rev}:{node|short}@{branch}({phase}) {desc|firstline}\n' "$@" | |
> } | |
$ shaof() { | |
> hg log -T {node} -r "first(desc($1))" | |
> } | |
$ mkcommits() { | |
> for i in $@; do mkcommit $i ; done | |
> } | |
Creating And Updating Changeset | |
=============================== | |
Setup the Base Repo | |
------------------- | |
We start with a plain base repo:: | |
$ hg init main; cd main | |
$ cat >main-file-1 <<-EOF | |
> One | |
> | |
> Two | |
> | |
> Three | |
> EOF | |
$ echo Two >main-file-2 | |
$ hg add | |
adding main-file-1 | |
adding main-file-2 | |
$ hg commit --message base | |
$ cd .. | |
and clone this into a new repo where we do our work:: | |
$ hg clone main work | |
updating to branch default | |
2 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
$ cd work | |
Create First Patch | |
------------------ | |
To begin with, we just do the changes that will be the initial version of the changeset:: | |
$ echo One >file-from-A | |
$ sed -i'' -e s/One/Eins/ main-file-1 | |
$ hg add file-from-A | |
So this is what we would like our changeset to be:: | |
$ hg diff | |
diff --git a/file-from-A b/file-from-A | |
new file mode 100644 | |
--- /dev/null | |
+++ b/file-from-A | |
@@ -0,0 +1,1 @@ | |
+One | |
diff --git a/main-file-1 b/main-file-1 | |
--- a/main-file-1 | |
+++ b/main-file-1 | |
@@ -1,1 +1,1 @@ | |
-One | |
+Eins | |
To commit it we just - commit it:: | |
$ hg commit --message "a nifty feature" | |
and place a bookmark so we can easily refer to it again (which we could have done before the commit):: | |
$ hg book feature-A | |
Create Second Patch | |
------------------- | |
Let's do this again for the second changeset:: | |
$ echo Two >file-from-B | |
$ sed -i'' -e s/Two/Zwie/ main-file-1 | |
$ hg add file-from-B | |
Before committing, however, we need to switch to a new bookmark for the second | |
changeset. Otherwise we would inadvertently move the bookmark for our first changeset. | |
It is therefore advisable to always set the bookmark before committing:: | |
$ hg book feature-B | |
$ hg --config extensions.commitextras commit --extra tagged=feature-b --message "another feature (child of $(hg log -r . -T '{node|short}'))" | |
So here we are:: | |
$ hg book | |
feature-A 1:568a468b60fc | |
* feature-B 2:73296a82292a | |
Fix The Second Patch | |
-------------------- | |
There's a typo in feature-B. We spelled *Zwie* instead of *Zwei*:: | |
$ hg diff --change tip | grep -F Zwie | |
+Zwie | |
Fixing this is very easy. Just change:: | |
$ sed -i'' -e s/Zwie/Zwei/ main-file-1 | |
and **amend**:: | |
$ hg amend | |
This results in a new single changeset for our amended changeset, and the old | |
changeset plus the updating changeset are hidden from view by default:: | |
$ hg log | |
3 feature-B: another feature (child of 568a468b60fc) - test | |
1 feature-A: a nifty feature - test | |
0 : base - test | |
$ hg up feature-A -q | |
$ hg bookmark -i feature-A | |
$ sed -i'' -e s/Eins/Un/ main-file-1 | |
(amend of public changeset denied) | |
$ hg phase --public 0 -v | |
phase changed for 1 changesets | |
(amend of on ancestors) | |
$ hg amend | |
1 new orphan changesets | |
$ hg log | |
4 feature-A: a nifty feature - test | |
3 feature-B: another feature (child of 568a468b60fc) - test | |
1 : a nifty feature - test | |
0 : base - test | |
$ hg up -q 0 | |
$ glog --hidden | |
o 4:ba0ec09b1bab@default(draft) a nifty feature | |
| | |
| * 3:6992c59c6b06@default(draft) another feature (child of 568a468b60fc) | |
| | | |
| | x 2:73296a82292a@default(draft) another feature (child of 568a468b60fc) | |
| |/ | |
| x 1:568a468b60fc@default(draft) a nifty feature | |
|/ | |
@ 0:e55e0562ee93@default(public) base | |
$ hg log -r 3 -T '{join(extras, " ")}\n' | |
*tagged=feature-b* (glob) | |
$ hg --config extensions.debugretainextras --config retain_extras=tagged evolve | |
move:[3] another feature (child of 568a468b60fc) | |
atop:[4] a nifty feature | |
merging main-file-1 | |
$ hg log -r 5 -T '{join(extras, " ")}\n' | |
*tagged=feature-b* (glob) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment