Diff after committing locally

别等时光非礼了梦想. 提交于 2021-02-10 19:52:27

问题


I just cloned a repo from their remote.

I built the software, changed about 4 files, committed them locally and now want to create a patch that I can show them.

When I run :

hg diff -U8p abc efg pqr > patch_file

I don't see the changes I made. Does hg diff only compare the current files with the last committed files?

How do I get this to work?


回答1:


  1. To diff the working directory against a particular revision REV, use

    hg diff -r REV 
    
  2. To compare two revisions against each other, use

    hg diff -r REV1 -r REV2
    
  3. To figure out which revisions to compare, examine the output of hg log. If you'll be doing this a lot and the base revision is fixed, give it a name (e.g., whatipulled) with

    hg tag -r REV whatipulled
    

    You can then specify whatipulled as the revision, instead of a numeric rev id (or a hash).

  4. To export your diffs in a richer format, including commit comments etc., you can also use the following which is designed for this purpose:

    hg export -r REV
    
  5. There's also hg bundle -r REV, which produces a binary file with similar information.

  6. But if you're sending changes back to the parent repo, the best method is to use hg push. It communicates your changesets directly to the parent; you don't even need to know which changesets need pushing. Of course, you must have the right to push to the parent repo.

    hg push [ parent_repo_url ]
    

    (If you pulled from it, mercurial should already know the path and you can leave it out).

  7. If the parent repo is on bitbucket and you don't have pu, you can set up your own account on bitbucket, pull/push to that from your local repo, and then issue a "pull request" to the project repo, asking them to pull from you.

All of the above have options to control their behavior, which see.




回答2:


From hg help diff

If only one revision is specified then that revision is compared to the working directory

In your diff for -r you must to use old tip (latest "not your" changeset) and update to tip (your latest changeset) before diffing.

If some binary data was modified in your changesets, don't forget to use -g option

hg up & hg diff -r <CSET> -g > some.patch

Improved diff for any active changeset and without hand-work for detecting base changeset (for linear history == in single branch)

hg diff -r "parent(min(outgoing()))" -r tip




回答3:


By default, hg diff compares the currently checked out file with the last commit. You can change this by adding options:

  • -r REV compares the currently checked out files with a specific revision REV.
  • -c REV shows the changes made by revision REV

So in your case hg diff -c 123 ... would give you the diff for commit 123.




回答4:


My guess is that hg outgoing is exactly what you want -- it compares what you've committed locally with what is at the default remote server and shows you a list of those changesets or with -p the commits.

That does, however, shows each changeset separately. If you want to see all the changes combined, you'd have to do hg diff -r HERE -r THERE or since -r HERE is a default, hg diff -r THERE

I see you've asked in a comment "How do I know what THERE is", where THERE is the last changeset remote has, and you can get that answer by doing hg outgoing. If hg outgoing shows it would send changesets 66, 67, and 68, then you want to do hg diff -r 65 to compare what's already there (65) with what's local (68).



来源:https://stackoverflow.com/questions/15051591/diff-after-committing-locally

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!