Domanda

In one of the commits that I want to cherry-pick from Branch B to Branch A, there are four files that changed, but I only want one of the files in that commit to be on Branch A. How do I get that file on Branch A? Thanks!

È stato utile?

Soluzione

It's a little bit of a hassle but this works:

If you have more files you don't want to commit then files you want to commit:

git checkout BranchA
git cherry-pick <sha1>
git reset HEAD^
git add <file>
git commit
git reset --hard

If you have more files to commit then not:

git checkout BranchA
git cherry-pick --no-commit <sha1>
git reset HEAD <file>
git commit

Altri suggerimenti

One option would be git show -p COMMIT_HASH:path/to/file > path/to/file to grab the file which has changed and then add and commit.

cherry-pick, revert all files but the one you want, commit amend:

git cherry-pick BranchB
git show --pretty=format: --name-only | grep . | grep -v fileyouwant | xargs git checkout HEAD^ -- 
git commit -a --amend -C HEAD
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top