问题
How to export patch for a single file without committing first(working directory)?
this is a possible duplicate, but my question is a little different and that question does not exactly give me a solution for my problem. Also, If I copy a patch how can I use it later? Plus it can be done with a commit only, yes it's a local commit and I can revert it later but is there a easier way?
回答1:
hg diff -g filename >patch
will generate the patch. The file can be in the modified or added state, but not untracked. -g
is "git" format, and can handle binary files, if needed.
hg import --no-commit patch
will import it to the working directory. There can't be other uncommitted files unless you also use -f
to force that patch to apply.
Edit per comment:
In TortoiseHg, to export patch for one file in working directory:
- Select the commit Window and the working directory.
- Right-click the file you want to create a patch for.
- Select
Copy patch
. - Open Notepad or similar editor.
- Paste.
- Save the file where you want.
To import that patch back to the working directory.
- Ensure there are no uncommitted files. Shelve if you don't want to commit.
- Select Repository menu, Import patches...
- Browse to the patch.
- Select "patches will be imported to...Working Directory"
- Click Import.
- Unshelve if needed.
OR
- CTRL-L to open a console in TortoiseHg.
- Use the
hg diff
andhg import
commands above. It's easier :)
来源:https://stackoverflow.com/questions/34804230/tortoisehg-how-to-export-patch-for-a-single-file-without-committing-first