我怎样才能安全地更新(拉)一个git项目,保持特定文件不变,即使有上游变化?
myrepo /配置/ config.php中
有没有办法,即使这个文件在远程更改,当我git pull,其他一切都更新,但这个文件没有改变(甚至没有合并)?
PS.我需要做我要问的事,因为我只是在编写基于git的部署脚本.我无法将配置文件更改为模板.
所以,我需要编写不会丢失本地更改的更新脚本.我希望有一些简单的事情:
git assume-remote-unchanged file1
git assume-remote-unchanged file2
Run Code Online (Sandbox Code Playgroud)
然后 git pull
GoZ*_*ner 232
有一个基于Git存储的简单解决方案.存放你已经改变的所有东西,拉出所有新东西,应用你的藏匿处.
git stash
git pull
git stash pop
Run Code Online (Sandbox Code Playgroud)
在藏匿的流行音乐上可能存在冲突.在您描述的情况下,实际上会发生冲突config.php.但是,解决冲突很容易,因为你知道你在藏匿处放置的是你想要的东西.这样做:
git checkout --theirs -- config.php
Run Code Online (Sandbox Code Playgroud)
Kur*_*tal 15
如果您的仓库中有一个文件,它应该由大多数拉拔器定制,那么将文件重命名为类似的config.php.template并添加config.php到您的.gitignore.
如果存在本地未提交的更改,以避免拉取时发生合并冲突:
git stash save
git pull
git stash pop
Run Code Online (Sandbox Code Playgroud)
来源:
https://git-scm.com/docs/git-stash
小智 6
我们还可以尝试 git pull 和 rebase
git pull --rebase origin dev
Run Code Online (Sandbox Code Playgroud)
更新:这从字面上回答了所提出的问题,但是我认为KurzedMetal的答案确实是您想要的。
假如说:
mastermaster在origin....您可以这样做:
# Do a pull as usual, but don't commit the result:
git pull --no-commit
# Overwrite config/config.php with the version that was there before the merge
# and also stage that version:
git checkout HEAD config/config.php
# Create the commit:
git commit -F .git/MERGE_MSG
Run Code Online (Sandbox Code Playgroud)
如果需要经常使用别名,则可以为其创建一个别名。请注意,如果您尚未提交对的更改config/config.php,则会将其丢弃。
| 归档时间: |
|
| 查看次数: |
123161 次 |
| 最近记录: |