Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
340 views
in Technique[技术] by (71.8m points)

git - Divert changes of specific files to new branch

I have 186 commits and would now like to split out changes made to two of those files into a separate branch. I changed 38 other files ("non-experimental" changes) and am trying to find what and why they were changed. The two files are config files with no dependencies, were added at the beginning of this feature branch and compose most of the commits so it should be possible to isolate them in a new branch.

I could rebase and squash them all, and them isolate the files in a single separate commit (reset --mixed then stage only those files), but I'm not ready to lose the entire history - I'm trying to review the history of the non-experimental files in the feature branch.

I've been trying to create a new branch and isolate the "non-experimental" changes. Nothing I've tried is automated, it always get kicked out as manual.

When I tried:

exec git rm C:/Experiment/Folder -r; git commit --amend --no-edit --allow-empty

rebase will stop saying there is a conflict that the file was both edited and deleted.

When I tried:

exec echo '' > C:/Experiment/Folder/File1.txt; 
  echo '' > C:/Experiment/Folder/File2.txt; 
  git commit -a --amend --no-edit --allow-empty

rebase stops saying it has conflicting edits.

Is there an automated or mostly automated way to do this, something short of visiting each commit and manually splitting, then reordering the ones needed?

If this is not clear

I have this:

* 76282bb4 (HEAD -> feature) Changed a.config
* fd1d5045 Changed a.config, b.config
* ec89d65a Changed b.config
* ba9199c2 Changed b.config
* 63d9197c Changed b.config, otherfile1.code
* 6133901d Changed a.config, otherfile3.code
* 48c66eff Changed a.config
* 39ee846f Changed a.config, b.config, otherfile1.code
* 54bbc5d1 Changed a.config, b.config
* 9113dbc7 Changed a.config, b.config
* babc1b65 Changed a.config, b.config
* ff627343 Changed a.config, b.config, otherfile1.code
* 1e6e67d5 Changed a.config, b.config
* ea98ea6f Changed a.config, b.config
* 67eecb9d Changed a.config, b.config, otherfile1.code
* 7d3fecc9 Changed a.config, b.config
* 75ad7ec7 Changed a.config, b.config
* 00a7c690 Changed b.config
* 834f64d3 Changed b.config
* e5989e3f Changed b.config
* 67b76c05 Changed b.config, otherfile2.code
* 99983077 Changed b.config
* df5a9112 Changed b.config
* b31a087d Changed b.config
* 684c4ade Changed b.config
* 00a2caf4 Changed a.config, b.config, otherfile1.code
* 4e597f2a Changed a.config
* 6516a036 Changed a.config
* d630d151 Changed a.config
* 8c475f53 Changed a.config
* 0c96e050 Changed a.config, b.config
* 51767ed3 Changed a.config, otherfile1.code
* 941f4690 Changed a.config
* a4172529 Changed a.config, b.config
* 734ea51f Changed a.config, b.config
* 0f85b9a1 Changed a.config, b.config
* deb9b8fe Changed a.config, b.config
* e7092fd9 Changed b.config
* ec9a6ab1 Changed b.config
* a0c9ef56 Changed b.config, otherfile1.code
* 9fbed040 Changed b.config
* 6c774f0a Changed b.config
* c1641dc5 Changed b.config, otherfile1.code
* 198982b1 Changed b.config
* ce780154 Changed a.config
* 862f18a3 Changed a.config
* 0159374c Changed a.config
* 43cd70fb Changed a.config, b.config, otherfile2.code
* a5ce4c92 Changed a.config

I want to see this:

* 63d9197x Changed otherfile1.code
* 6133901x Changed otherfile3.code
* 39ee846x Changed otherfile1.code
* ff62734x Changed otherfile1.code
* 67eecb9x Changed otherfile1.code
* 67b76c0x Changed otherfile2.code
* 00a2cafx Changed otherfile1.code
* 51767edx Changed otherfile1.code
* a0c9ef5x Changed otherfile1.code
* c1641dcx Changed otherfile1.code
* 43cd70fx Changed otherfile2.code

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...