Git cherry-pick merge removal file

I am trying to make a cherry-pick commit in git that adds a bunch of files, but also modifies a file that does not exist in my branch yet.

There is a conflict in which all the files that need to be added, everything, and the file that was changed in the commit, but does not yet exist in the branch, is not set and is indicated as:

deleted by us: app/changed_file.rb 

If I just commit the delivered files, it will cause problems when changed_file.rb will eventually be merged with the branch?

+4
source share
2 answers

https://www.kernel.org/pub/software/scm/git/docs/git-cherry-pick.html

Cherry-pick creates a new commit, so if you omit a file that does not exist in your branch but exists in the branches, you are going to merge, eventually nothing will happen.

 mkdir test && cd test && git init && touch foo.txt git add foo.txt && git commit -m "Init repo" git branch test && git checkout test && vi foo.txt git add foo.txt && git commit -m "Changed foo on branch test" git checkout master && touch bar.txt git add bar.txt && git commit -m "Create bar.txt" vi bar.txt touch baz.txt && git add . && git commit -m "Will be cherry picked" git checkout test && git cherry-pick bfd1b58 git rm bar.txt && git commit git checkout master && git merge test 

And as a result, ls : bar.txt baz.txt foo.txt

+3
source

You can simply remove this file from the commit you selected on the cherry, if it is not required ...

git rm filename

git commit

- make sure your commit message contains the line Change ID: line as the last paragraph

git push origin HEAD: refs / for / branch_name

This way you will not get any conflicts, and this will facilitate your merger next time.

+1
source