Here's what I did. I don't want two heads. How do I fix this?
~/src: hg push
pushing to ssh://hg#bitbucket.org/Neil/project
ruprojecting ssh hg#bitbucket.org 'hg -R Neil/project serve --stdio'
searching for changes
new remote heads on branch 'default'
new remote head e04226a528b5
abort: push creates new remote head e04226a528b5!
(did you forget to merge? use push -f to force)
~/src: hg push -f
pushing to ssh://hg#bitbucket.org/Neil/project
ruprojecting ssh hg#bitbucket.org 'hg -R Neil/project serve --stdio'
searching for changes
14 changesets found
remote: adding changesets
remote: adding manifests
remote: adding file changes
remote: added 14 changesets with 30 changes to 67 files (+1 heads)
remote: bb/acl: Neil is allowed. accepted payload.
~/src: hg pull
ruprojecting ssh hg#bitbucket.org 'hg -R Neil/project serve --stdio'
pulling from ssh://hg#bitbucket.org/Neil/project
searching for changes
no changes found
~/src: hg heads
changeset: 1177:e04226a528b5
tag: tip
parent: 1175:b5f77a454e64
user: Neil
date: Sat Feb 25 09:12:48 2012 -0800
files: src/experiments/distribution_combination.py
changeset: 1176:f7cc8d94f4f3
parent: 1162:b680e6f93f80
user: Neil
date: Thu Feb 23 15:32:36 2012 -0800
files: .hgignore src/CMakeLists.txt etc.
If you don't want additional heads - don't do it
Instead of dumb push -f:
hg incoming && hg pull
hg merge
hg commit
hg push
hg merge
That will prompt you to merge the two heads back into one. Rather, it will merge everything it can automatically, and prompt you about conflicts. Afterwards you can diff the result and submit it as a new changelist.
This is usually an indication that someone else has pushed since you last pulled. While you can provide the -f flag to force the push, as you have seen this just results in a new head.
The solution is to update to the head that you want to merge into, and run hg merge, then commit/push.
Related
I have modified, committed and pushed: fileA, fileB, and fileC. I should only have pushed "fileA" and "fileB", and my pull request has been declined due to this unwanted fileC.
Baring in mind that I have pushed these changes to the remote repository, is there a way for me to fix this locally so my pull request will not include fileC any more?
Simply create a new head with all necessary commits, starting to branch-off at the same parent where your 'wrong' changeset is based on. Then create a new pull-request for that new head you thus created.
Afterwards, you can opt to remove the unwanted head with the changeset(s) which include the unwanted fileC, however that should not be necessary. The strip command will come in handy for that (it's an extension and needs activation in your mercurial config file)
There are 2 ways doing that:
1- Fixing the repository and correcting the history so your incorrect commit is also cleaned from the history:
a- do a git log:
Desphilboy#computer:~/workspace/project(master)$ git log
commit dee4f318231b07ca3dbf213579dbfdeb89f72591
Author: Desphilboy<desphilboy#yahoo.com>
Date: Wed Jul 13 11:04:43 2016 +1000
feat(project): this is a wrong commit pushing FileC
commit e9772baa0abefc3423db2e6b518c71bade74abd9
Author: Somebody else<someoneelse#yahoo.com>
Date: Tue Jul 12 12:05:18 2016 +1000
feat(project): added new API endpoint
....
b- do a reset --soft to the hash code before that wrong commit:
Desphilboy#computer:~/workspace/project(master)$ git reset --soft e9772baa0abefc3423db2e6b518c71bade74abd9
this will revert your commit while keeping all your changes. if you do a git status now you will see all your changes after that commit
c- delete FileC and do another commit and push it again using -f switch
Desphilboy#computer:~/workspace/project(master)$ rm FileC
Desphilboy#computer:~/workspace/project(master)$ git rm FileC
Desphilboy#computer:~/workspace/project(master)$ git add .
Desphilboy#computer:~/workspace/project(master)$ git commit -m "some commit message"
Desphilboy#computer:~/workspace/project(master)$ git push -f
2- Keeping history:
you can simply delete the fileC, remove it from repo, commit and push your local to the master again. this will correct your problem but there will be an additional commit to the master and it will be shown in the history.
Let's say I have a changeset I've tagged as "stable". Now I update to "stable" and then start writing my new feature, committing along the way. It's not ready yet, so I don't want to merge it back into stable at this point, but I need to go fix an urgent bug on another branch.
I update to the branch, fix the bug, and commit my changes. Now I want to get back to where I left off, how do I do that?
I can "tag" my feature branch so that I can find it again, but AFAIK tags don't float along my branch as I commit, so it will always be a few revisions behind. This is good for "stable" because I don't want that tag to move, but bad for my feature branch.
How do I deal with this?
It just occurred to me that I can hg up <tag> and then run hg up a second time, and that will bring me to the tip of the branch, no? Seems a bit awkward to run hg up twice in a row, but if that's the Mercurial way of doing things, so be it.
In Mercurial a bookmark is a tag that moves forward whenever you commit. It sounds like precisely what you want:
(df)ry4an-mba:~ ry4an$ hg init smooth_reggae
(df)ry4an-mba:~ ry4an$ cd smooth_reggae/
(df)ry4an-mba:smooth_reggae ry4an$ echo this > AFILE
(df)ry4an-mba:smooth_reggae ry4an$ hg commit -Am first
adding AFILE
(df)ry4an-mba:smooth_reggae ry4an$ hg bookmark stable
(df)ry4an-mba:smooth_reggae ry4an$ hg checkout stable
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
(df)ry4an-mba:smooth_reggae ry4an$ hg summary
parent: 0:fdb32de55e6b tip
first
branch: default
bookmarks: *stable
commit: (clean)
update: (current)
(df)ry4an-mba:smooth_reggae ry4an$ echo more >> AFILE
(df)ry4an-mba:smooth_reggae ry4an$ hg commit -Am second
(df)ry4an-mba:smooth_reggae ry4an$ hg summary
parent: 1:38cdabce7149 tip
second
branch: default
bookmarks: *stable
commit: (clean)
update: (current)
(df)ry4an-mba:smooth_reggae ry4an$ hg log -g
changeset: 1:38cdabce7149
bookmark: stable
tag: tip
user: Ry4an Brase <ry4an-hg#ry4an.org>
date: Wed May 08 20:02:05 2013 -0400
summary: second
changeset: 0:fdb32de55e6b
user: Ry4an Brase <ry4an-hg#ry4an.org>
date: Wed May 08 20:01:31 2013 -0400
summary: first
Are you using an unnamed branch as your feature branch? If not, your branch surely has a name that you can use in hg up <branch_name> to get to its tip.
I did a series of dumb steps with my local copy of our shared repository, and I'm looking for a way how to fix it. The steps are:
I used bookmarks to have multiple heads of a development branch, that other people use:
-o---o---o-----o--- <- dev branch
\----1----1------ <- another head of the dev branch,
where I committed stuff
I created a new branch, still local, some time later
/---------------x <- new branch
-o---o---o-----o--- <- dev branch
\----1----1------ <- another head of the dev branch,
where I committed stuff
for one head, that contains only my code, I did a rebase on another branch
/-1'--1'-- <- rebase
/---------------x <- new branch
-o---o---o-----o--- <- dev branch
\----1----1------ <- another head of the dev branch,
where I committed stuff
then, I merged the rebase, and then, a couple of commits later, I merged default
----------d-\ <-default
\
/-1'--1'\ \
/---------------x--------x--x-x-x-- <- new branch
-o---o---o-----o---
\----1----1------
Now, I wanted to push my new branch to the server (hg push --new-branch -b newBranch), but I get abort: push creates new remote head, since commits 1' belong to dev branch.
What is the right thing to do? I would like to avoid creating this additional head.
Update:
Per request, this is the output of hg heads:
changeset: 839:f2033d695fcd <- want to push this
branch: newBranch
tag: tip
user: me
date: Wed Oct 31 13:05:51 2012 +0100
changeset: 826:7fde19d7f467
branch: devBranch
user: my-collegue
date: Tue Oct 23 14:59:42 2012 +0200
changeset: 820:23853bbf68df <- the part after rebase that got merged
branch: devBranch
user: me
date: Mon Oct 22 15:36:26 2012 +0200
changeset: 807:899344cfb145 <- obsolete (branch with 1's)
branch: devBranch
parent: 711:454f29c03fb1
user: me
date: Mon Oct 22 15:36:26 2012 +0200
changeset: 712:d5e8a62a7f5f <- default, needs to stay
parent: 648:2bbcc01aa191
user: me
date: Wed Aug 22 16:21:09 2012 +0200
You can push only the one head you're interested in mercurial. For you that would mean doing:
hg push -r f2033d695fcd
If the destination repo has been updated you need to pull, merge, and re-push:
hg pull
hg up -r <remote head>
hg merge -r f2033d695fcd
hg ci
hg push
I solved the problem, without pushing another head to the repo, and without merging 23853bbf68df onto newBranch. This is probably not the cleanest way to do it, but I will leave it as a reference. In a nutshell, I reconstructed the whole branch by taking all commits and re-applying them.
First, I killed the newBranch'es head 899344cfb145, by using strip on the first diverging revision I did:
hg strip -r 646
Then, I produced email patches (couldn't play with mq) for all commits that are in newBranch, since it's inception:
hg export -g -r 797:808 -r 810 -r 815:822 -r 824:830 -o "%n-%m.patch"
797:808 are the patches in newBranch that were in the rebased part of devBranch (1' commits from the original figure).
810 and 815:822 are other patchs in newBranch. 811:814 belong to a different branch, so I had to exclude those.
823 is a merge commit with default, so I skipped this one.
824:830 are all the commits after the merge with default.
Now, I imported these patches on a new head of newBranch:
hg up -r 796
# there are 29 patches, applying till merge
hg import --bypass {01..21}*.patch
hg up tip
hg merge default
hg ci -m 'merging in default'
hg import --bypass {22..28}*.patch
Finally, I just stripped of the original head of newBranch.
hg strip -r 797
This may not work in every situation. During the merge, I had to resolve some conflicts, too, but pretty benign. Hope this helps someone.
I have a Windows file structure like so:
Stable
ProjectA
SharedLibrary
Stable contains the main repo. ProjectA and SharedLibrary are subrepos of Stable. The .hgsub file contains:
ProjectA = ProjectA
SharedLibrary = SharedLibrary
Everything seems to work correctly for the most part. The main repo will recognize the subrepos, and I can do things like hg status -S on the main repo and it will recurse through the subrepos. commit also seems to work correctly.
When I try to clone from Stable (main repo), it fails when attempting to clone the ProjectA subrepo with the following message:
unknown revision 'a855f4fe17c393d5863409f1443fc93b36787fa9'
[command returned code 255 Mon Mar 12 09:25:47 2012]
However, I have verified that the revision is correct and present in the ProjectA subrepo. I can clone each subrepo without any problems.
So far I have tried:
1) Deleting each repository and starting over.
2) Re-installing TortoiseHg/Mercurial.
3) Making sure the revision listed in .hgsubstate is correct and present in each subrepo.
Any way to fix this?
EDIT:
When the clone of the Stable (main) repo fails, it leaves the target directory with a clone of Stable without any subrepos. I can go to the cloned Stable, do an hg update tip, and it will successfully clone the ProjectA subrepo but fail to clone SharedLibrary with the same 'unknown revision' error. I can then run hg update tip again, and it will successfully clone the SharedLibrary subrepo. At that point everything is correct as it would be if the clone had worked correctly in the first place.
EDIT 2: Contents of .hgsubstate:
a855f4fe17c393d5863409f1443fc93b36787fa9 ProjectAd72ef29a5656e5413322c1d20d5830448d558605 SharedLibrary
There is no space between ProjectA and the changeset id for SharedLibrary, but I guess that is just the way Mercurial does it. Both changesets in .hgsubstate are present in the respsective subrepo.
EDIT 3: hg log --debug -r tip from ProjectA subrepo. showing correct changeset is present
Z:\Programming\KSuite\Stable\Client\KClient>hg log --debug -r tip
changeset: 4:a855f4fe17c393d5863409f1443fc93b36787fa9
tag: tip
parent: 3:eb01e88027c893267422fcb67f035ba31d8cdbdc
parent: 2:5b5ffd7f96915ca792507820ccfbee35707148d0
manifest: 4:e90960833c0708ec7f99ccded11c46ca45b46542
user: Casey ******** <*redacted*#.com>
date: Fri Mar 09 18:22:50 2012 -0500
files: .hgignore
files-: KClient.suo
extra: branch=default
description:
Merging changes in Stable to Dev.
I can't figure out why i'm still unable to push to a remote repository:
> hg pull
pulling from ......
searching for changes
no changes found
> hg merge
abort: branch 'default' has one head - please merge with an explicit rev
(run 'hg heads' to see all heads)
> hg heads
changeset: 12942:...
tag: tip
parent: 12940:...
parent: 12941:...
summary: merge
> hg branches
default 12942:...
> hg commit
nothing changed
and finally
> hg push
pushing to ...
searching for changes
abort: push creates new remote heads on branch 'default'!
(did you forget to merge? use push -f to force)
why would that be?
Not sure why, but this solved the issue:
hg push -r tip
where -r is
-r --rev REV [+] a changeset intended to be included in the destination