when I pull patch from gerrit,a question come:
what's difference between the 'git apply' and 'git fetch'?
cp patch /the/path/save
git apply patch
and
git fetch ssh://someone@gerrit.(SOME INFOMATION) && git cherry-pick FETCH_HEAD
Are they the same thing? or do a first and then b
a,b can‘t be done at the same time.It seems that they do the same thing,but I still cannot understand what difference between them.
CodePudding user response:
Even if fed the same commit contents, the result will differ:
git cherry-pick
will create a commit that's a copy of the specified commit and retain the original commit information (author, author-date, commit message)git apply
will read a diff/patch file and apply it to your current working directory.
It will not create a commit and if you do commit the resulting changes, the original commit information will not be in that commit.
(Unless you manually add it yourself)
However, there's also git am -k
which you can use to import a patch created by git format-patch -k
. Then you should end up with a commit that's a copy of a commit, similar to cherry-picking.
https://git-scm.com/docs/git-am https://git-scm.com/docs/git-format-patch