简体   繁体   English

“git apply”和“git fetch”有什么区别?

[英]what's difference between the 'git apply' and 'git fetch'?

when I pull patch from gerrit,a question come:当我从 gerrit pull patch 时,一个问题来了:
what's difference between the 'git apply' and 'git fetch'? “git apply”和“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

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. a,b 不能同时做。看起来他们做的是同一件事,但我仍然无法理解它们之间有什么区别。

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 cherry-pick将创建一个提交,该提交是指定提交的副本并保留原始提交信息(作者、作者日期、提交消息)
  • git apply will read a diff/patch file and apply it to your current working directory. git apply将读取差异/补丁文件并将其应用到您当前的工作目录。
    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 .但是,还有git am -k可用于导入由git format-patch -k创建的补丁。 Then you should end up with a commit that's a copy of a commit, similar to cherry-picking.然后你应该以一个提交的副本结束,类似于 cherry-picking。

https://git-scm.com/docs/git-am https://git-scm.com/docs/git-format-patch https://git-scm.com/docs/git-am https://git-scm.com/docs/git-format-patch

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 &#39;git fetch&#39;和&#39;git fetch --all&#39;之间的区别是什么? - What's the difference between 'git fetch' and 'git fetch --all' git pull和git fetch + rebase有什么区别 - What's difference between git pull and git fetch+rebase git am 和 git apply 有什么区别? - What is the difference between git am and git apply? “git pull”和“git fetch”有什么区别? - What is the difference between 'git pull' and 'git fetch'? “git fetch”和“git fetch”有什么区别<url> ”和“git add远程上游<url> ”后跟“git fetch upstream”? - What's the difference between “git fetch <url>” and “git add remote upstream <url>” followed by “git fetch upstream”? `git fetch origin` 和 `git fetch git://127.0.0.1/` 有什么区别 - What's the difference between `git fetch origin` and `git fetch git://127.0.0.1/` TortoiseGit:“Git Sync”、“Fetch”和“Pull”有什么区别? - TortoiseGit: What's the difference between “Git Sync”, “Fetch” and “Pull”? `git fetch` 然后 `git rebase` 和 `git pull --rebase` 有什么区别? - What's the difference between `git fetch` then `git rebase`, and `git pull --rebase`? 'git remote update','git fetch'和'git pull'有什么区别? - What is the difference between 'git remote update', 'git fetch' and 'git pull'? git pull 和 git fetch + git rebase 有什么区别? - What is the difference between git pull and git fetch + git rebase?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM