programing tip

Mercurial을 사용하면 푸시하기 전에 일련의 변경 세트를 하나로 "압축"할 수 있습니까?

itbloger 2020. 8. 27. 07:26
반응형

Mercurial을 사용하면 푸시하기 전에 일련의 변경 세트를 하나로 "압축"할 수 있습니까?


로컬 및 원격 Mercurial 저장소가 있다고 가정 해 보겠습니다. 이제 기능 작업을 시작합니다. 작업을하고 끝났다고 생각되면 변경 세트를 커밋합니다. 좀 더 테스트 해보면 코드에서 무언가를 수정하여이 기능을 더욱 향상시킬 수 있다는 것을 알았습니다. 나는 변화를 만들고 헌신한다. 20 분 후이 새로운 기능에 버그가 있음을 알게되었으므로 수정하고 커밋합니다.

예를 들어 "Implementing feature X"라는 메시지와 함께 하나의 변경 집합으로 원격 저장소에 실제로 푸시하려는 3 개의 변경 집합이 있습니다.

번거롭지 않게 어떻게 할 수 있습니까? 나는 패치로 할 수 있다고 믿지만 많은 작업처럼 보입니다.


방법에 대한 축소 확장 ?


histedit의 확장은 당신이 찾고있는 정확하게이다.

hg histedit -o

또는

hg histedit --outgoing

나가는 변경 집합 목록이 나타납니다. 목록에서 다음을 수행 할 수 있습니다.

  • 하나의 변경 세트를 생성하는 2 개 이상의 변경 세트 접기
  • 기록에서 제거하는 변경 세트 삭제
  • 원하는대로 변경 세트를 재정렬하십시오.

histedit는 "\ n *** \ n"을 구분하는 두 개의 메시지로 기본 설정되는 접힌 변경 세트의 새 커밋 메시지를 묻는 메시지를 표시합니다.

mq 확장을 사용하여 유사한 결과를 얻을 수도 있지만 훨씬 더 어렵습니다.

접기 확장을 사용하여 접기 만 할 수도 있지만 좋은 UI를 제공하지 않으며 결과 커밋 메시지를 편집하는 방법을 제공하지 않습니다. 결과 커밋 메시지를 편집하면 최종 메시지를 정리할 수도 있습니다.


예, 패치로 할 수 있습니다 : 작업이 100부터 110까지의 변경 세트에 있다고 가정 해 보겠습니다.

  1. 패치 생성 :

    % hg export -o mypatch 100:110 --git

  2. 99로 업데이트 :

    % hg update 99

  3. --no-commit을 사용하여 패치를 적용합니다 (그렇지 않으면 모든 변경 세트를 다시 가져옵니다).

    % hg import --no-commit mypatch

  4. 모든 변경 사항을 한 번에 커밋합니다.

    % hg commit

  5. 이제 두 개의 헤드 (110 및 111)가 있으며 이는 작업 디렉토리에서 생성하는 파일 측면에서 동일해야합니다. 예전 파일을 제거하기 전에 온 전성을 위해 비교할 수도 있습니다.

    % hg strip 100

좋아, 이제 모든 철자를 다 써서 길어 보이지만 직접 여러 번 해본 결과 너무 많은 일이 아닙니다 ...


TortoiseHg를 사용하는 경우 두 개의 개정판을 선택하고 (다음이 아닌 개정판을 선택하려면 CTRL 사용) 마우스 오른쪽 버튼을 클릭 한 다음 "기록 압축"을 선택하십시오 .

그 후에는 이전에 선택한 첫 번째 변경 사항부터 새 헤드에 새 변경 목록이 표시되고 선택한 항목 사이의 모든 하위 변경 목록이 포함됩니다.

더 이상 필요하지 않은 경우 이전 변경 목록을 제거 할 수 있습니다 . MQ 확장을 사용하십시오. 다시 TortoiseHg에서 : 모든 하위 항목으로 제거해야하는 첫 번째 변경 목록 "Modify History-> Strip"을 마우스 오른쪽 버튼으로 클릭합니다 .


이 폴딩에 mq를 사용하는 선호하는 방법은 여기에 설명 된대로 TortoiseHg 를 사용하는 것 입니다. 그러나 다음과 같이 명령 줄에서 쉽게 수행 할 수 있습니다.

hg qimport -r <first>:<last> 
    -- where <first> and <last> are the first and last changesets 
    -- in the range of revisions you want to collapse

hg qpop <first>.diff
    -- remove all except for the first patch from the queue
    -- note: mq names patches <#>.diff when it imports them, so we're using that here

hg qfold <next>.diff
    -- where <next> is <first>+1, then <first>+2, until you've reached <last>

hg qfinish -a
    -- apply the folded changeset back into the repository

(qfold 단계를 수행하는 더 좋은 방법이있을 수 있지만 일반적으로 해당 작업에 TortoiseHg를 사용하므로 잘 모릅니다.)

It seems a little complicated at first, but once you've started using mq, it's pretty straightforward and natural -- plus you can do all kinds of other things with mq that can be pretty handy!


hg collapse and hg histedit are the best ways. Or, rather, would be the best ways, if they worked reliably... I got histedit to crash with a stack dump within three minutes. Collapse is not that much better.

Thought I might share two other BKMs:

  1. hg rebase --collapse

    This extension is distributed with Mercurial. I haven't had problems with it yet. You may have to play some games to work around hg rebase limitations -- basically, it doesn't like rebasing to an ancestor on the same branch, named or default, although it does allow it if rebasing between (named) branches.

  2. Move the repository (foo/.hg) to the working directory (bar) and its files. Not the other way around.

Some people have talked about creating two clone trees, and copying files between them. Or patching between them. Instead, its easier to move the .hg directories.

hg clone project work
... lots of edits
... hg pull, merge, resolve
hg clone project, clean
mv work/.hg .hg.work
mv clean/.hg work/.hg
cd work
... if necessary, pull, nerge, reconcile - but that would only happen because of a race
hg push

This works as long as the true repositories, the .hg trees, are independent of the working directory and its files.

If they are not independent...


I've never used Mercurial, but this sounds a lot like what Martin Fowler was talking about on his blog not too long ago:

http://martinfowler.com/bliki/MercurialSquashCommit.html


Why not just hg strip --keep command?

Then you can commit all changes as a one commit.


HistEdit will do what you want, but it's probably overkill. If the only thing you need is to fold some changesets together the Collapse Extension will do the job.


Suppose you have two unpublished THIS and THAT commits in Mercurial and like them to join into single commit at THIS point::

... --> THIS --> ... --> THAT --> ... --> LAST

Check that your commits are not published::

$ hg glog -r "draft() & ($THIS | $THAT)"

Update to LAST commit::

$ hg up

and import commits up to THIS into MQ::

$ hg qimport $THIS::.

Un-apply all patches and apply only first THIS::

$ hg qpop -a
$ hg qpush
$ hg qapplied
... THIS ...

Join with THAT::

$ hg qfold $THATNAME

NOTE To find name THATNAME use::

$ hg qseries

Apply all patches and move them to repository history::

$ hg qpush -a
$ hg qfinish -a

My blog post on subject is Joining two commits in Mercurial.


Yes, strip --keep works for Author's question. But it was slightly different from others, for example, if you have version from 1 to 30 but only want to collapse version 12-15. Other solutions work but not strip --keep.

참고URL : https://stackoverflow.com/questions/1200691/with-mercurial-how-can-i-compress-a-series-of-changesets-into-one-before-push

반응형