我在远程myrepo
服务器上有一个名为beanstalk
的仓库。
我把它克隆到我的本地机器上。创建了另外两个分支:staging
和dev
。将这些分支推向远程。
现在:
local remote server
--------------------------------------------------------
master ==> Pushes to `master` ==> deployed to `prod`
staging ==> Pushes to `staging` ==> deployed to `staging`
dev ==> Pushes to `dev` ==> deployed to `dev`
我有一个名为config.xml
的文件,每个分支都有不同的文件。
我想仅在合并期间忽略此文件。但是我希望在结帐或从/向repo分支提交时包含它。
我想要这个的原因是,我们有一个部署脚本,可以拉出(签出)特定分支并在各自的服务器上部署。所以我们需要特定分支的config.xml
文件在部署时如上所示进入特定服务器。
我想.gitignore
不会工作。还有什么其他选择?请注意,被忽略的文件应该是checkout和commit的一部分,这很重要。它只应在合并期间被忽略。
谢谢!
我通过使用带有--no-commit
选项的git merge命令解决了这个问题,然后显式删除了暂存文件并忽略了对文件的更改。例如:说我想忽略对myfile.txt
的任何更改我按如下方式进行:
git merge --no-ff --no-commit <merge-branch>
git reset HEAD myfile.txt
git checkout -- myfile.txt
git commit -m "merged <merge-branch>"
如果要有要跳过的文件列表,可以将语句2和3放在for循环中。
我最终找到了git attributes
。试试吧。到目前为止工作。尚未检查所有方案。但它应该是解决方案。
.gitattributes
- 是存储库的根级文件,用于定义子目录或文件子集的属性。
您可以指定该属性以告知Git对特定文件使用不同的合并策略。在这里,我们希望为我们的分支保留现有的config.xml
。我们需要在merge=ours
文件中将config.xml
设置为.gitattributes
。
如果发生合并冲突,merge=ours
告诉git使用我们的(当前分支)文件。
.gitattributes
文件.gitattributes
文件中为confix.xml设置属性
config.xml merge=ours
$ git config --global merge.ours.driver true
如果你合并stag
形式dev
分支,而不是让合并与config.xml文件冲突,stag branch的config.xml保留在你最初的任何版本。
您可以首先使用git merge --no-commit
,然后根据需要编辑合并,即通过取消暂存config.xml
或任何其他文件,然后提交。我怀疑你想在使用钩子后进一步自动化它,但我认为值得手动至少进行一次。
您可以使用.gitignore
将config.xml
保留在存储库之外,然后使用post commit hook将相应的config.xml
文件上载到服务器。
这里git-update-index - 将工作树中的文件内容注册到索引。
git update-index --assume-unchanged <PATH_OF_THE_FILE>
例:-
git update-index --assume-unchanged somelocation/pom.xml
例:
master
,develop
develop
分支中创建了文件,并希望在合并时忽略它码:
git config --global merge.ours.driver true
git checkout master
echo "path/file_to_ignore merge=ours" >> .gitattributes
git merge develop
您也可以忽略具有相同扩展名的文件
例如,所有带有.txt
扩展名的文件:
echo "*.txt merge=ours" >> .gitattributes