Mercurial/Hg; syntax/tips for amend commit adding/reming files to latest (non-pushed) commit
Posted by jpluimers on 2016/09/01
Sometimes your latest commit isn’t what you intended. Fixing can be done, but isn’t always obvious hence these links:
- Until you do a pull,
hg diff -c tip, orhg tip -pgets you the diff of the latest local commit
via Mercurial: Easy way to see changes from last commit – Stack Overflow. hg commit --amendfile allows you to add/update a file to the latest commit.
via Mercurial: how to amend the last commit? – Stack Overflow.- Removing a file from the latest commit is a bit more tricky as it depends if the file is new, or existing. Example is below.
More details via Remove file from a commit in Mercurial – Stack Overflow. Examples
Remove a new file from a commit:
cp somefile.txt somefile.txt.bak
hg forget somefile.txt
hg commit --amend
If the file was new (i.e. you had used hg add).
If that file already existed try:
cp somefile.txt somefile.txt.bak
hg revert somefile.txt --rev .~1
hg commit --amend
cp somefile.txt.bak somefile.txt
–jeroen






Leave a comment