Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@yurydelendik
Last active May 12, 2018 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yurydelendik/a79b350aa2d7fa71136683f60a6c60c2 to your computer and use it in GitHub Desktop.
Save yurydelendik/a79b350aa2d7fa71136683f60a6c60c2 to your computer and use it in GitHub Desktop.
Some version control operations

Overview

Provides set of operations to efficiently maintain set of patch for long time and be able to submit those for review.

GIT

Let's say we clone a repo and 'master' is upstream branch and we will keep it up-to-date on regular base.

We can created a branch for a new feature and will try to keep it fresh and with addressed reviews.

  • Reset 'master' branch git checkout -B master upstream/master and pull changes git pull
  • Start a new branch 'feature': git checkout -b feature master
  • Addressing reviews by creating new commit for every old commit (or even per change)
  • Squashing old and new commits:
    • git rebase -i HEAD~<n> (where n = amount of affected old commits + new commits)
    • new commits can be moved around (after related old commit) and prefix changed to 'f'
  • Refreshing base from master: git rebase --onto master feature~<n> feature (n = amount of commits in the 'feature')
  • Push refreshed/updated branch: git push -f origin feature

HG (mq)

Let's say we clone a repo and we will keep our new feature patches in the queue (one feature at a time?)

  • Reset repo: hg revert -a && hg qpop -a then hg pull && hg update
  • After reset, one-by-one adding patches from queue hg qpush (resolve conflicts then hg qrefresh)
  • During addressing of the review, move back to forward using to the needed changeset hg qpop and hg qpush add change then hg qrefresh
  • Patches can be exported via hg export <name> (where name is id in the queue)

HG (bookmarks)

Let's say we clone a repo and we will keep our feature patches at various bookmarks.

  • Create master bookmark before: hg bookmark master
  • Clear and start new bookmark clean: hg revert -a && hg update master -C and hg bookmark feature
  • List changeset without other bookmarks: hg log -r feature -f -l 10
  • Refresh base: hg rebase -s <id> -d master (id is oldest feature commit)
  • Append changes:
    • to last commit hg commit --amend
    • to commit with children: hg update 'parents(<id>)' && hg export <id> | hg import --no-commit -, append new changes, hg commit -e --amend (previous commit message hg log -r <id> --template='{desc}')
  • Append commit without change hg export <id> | hg import -
  • Append commit and children and update their bookmarks hg rebase -s <id>

~/.hgrc stuff

[alias]
cmsg = !$HG log -r "$1" --template '{desc}'
cvim = !vi `$HG root`/.hg/last-message.txt
cget = !$HG log -r "$1" --template '{desc}' > `$HG root`/.hg/last-message.txt && \
       $HG export "$1" | $HG import --no-commit -
ccopy = !$HG export "$1" | $HG import -
cci = !$HG ci -l `$HG root`/.hg/last-message.txt

stu = !$HG status -u "$1" | awk '{print $$2}'
slh = !$HG heads -T '{node|short} {bookmarks}\n' | grep -e '\s$$'
gclh = !$HG slh | xargs $HG strip --no-backup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment