- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我对 git 和我的存储库有疑问。
先写例子
git checkout Proj1
# modify index.html
git commit -am "Modify Index.html"
git checkout Proj2
git show Proj1:index.html > index.html
git commit -am "Modify Index.html"
git checkout Proj1
这是我在两个分支中保留相同文件内容的方法。
当然,如果提交仅包含我要同步的文件,我可以使用 cherry-pick。 How can we sync files between two branches in git?
对于这个问题,你有什么简短的解决方案吗?
也许要写一些别名?
我可以在哪里保存包含要同步的文件列表的文件?
最佳答案
如果您不关心历史记录,那么您可以在分支 2 上进行单独的提交,其中包含的文件与 Proj1 中提交提示中的文件完全相同:
git checkout Proj2
git checkout Proj1 -- index.html
git commit -am "Modify Index.html"
本质上,这意味着完全按照它在 Proj1 分支中的样子获取文件。
git checkout --
表示在破折号之后你提供了一个文件名(或路径)。如果您想更改存储库中的某些文件并保留其他文件,这也很有用。
然后,如果需要,您还可以像这样重用您在 Proj1 中所做的提交中的提交消息:
git checkout Proj2
git checkout Proj1 -- index.html
git commit -a -C Proj1
Git commit -C
意味着重用您已经拥有的提交评论。
来自git documentation "git checkout" :
git checkout
[-p|--patch] [<tree-ish>] [--] <pathspec>
When or
--patch
are given, git checkout does not switch branches. It updates the named paths in the working tree from the index file or from a named (most often a commit).[...]
git checkout with or
--patch
is used to restore modified or deleted paths to their original contents from the index or replace paths with the contents from a named (most often a commit-ish).
并且来自 git documentation "git commit"
git commit -C <commit>
--reuse-message=<commit>
Take an existing commit object, and reuse the log message and the authorship information (including the timestamp) when creating the commit.
关于git - 如何在git中的两个分支之间同步一些文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36419916/
我是一名优秀的程序员,十分优秀!