简体   繁体   English

Git - 如何从 git diff 生成提交

[英]Git - How to generate a commit from git diff

I am in main branch and there are some mismatches in main and dev .我在main分支, maindev有一些不匹配。 I can see the diff in a specific folder using,我可以使用以下命令查看特定文件夹中的差异,

git diff main..dev Code/Folder/*

Now I want to move all the changes the diff showing inside the Code/Folder/* into a new commit in current branch, main.现在我想将Code/Folder/* 中显示的所有更改移动到当前分支 main 中的新提交中。

How do I do that?我怎么做?

You can use git checkout <branch> <path> form like:您可以使用git checkout <branch> <path>形式,例如:

git checkout main
git checkout dev Code/Folder
# ... you may fix unwanted changes here ...
git commit -m "import Code/Folder from dev branch"

It will overwrite <path> with <branch> 's content without switching current branch.它将用<branch>的内容覆盖<path>而不切换当前分支。

Below code works fine (adding changes into main from dev),下面的代码工作正常(从 dev 向 main 添加更改),

git checkout main
git diff main..dev Code/Folder/* | git apply
git add *
git commit -s -m "Adding diffs to main from dev for Code/Folder/*"

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM