在处理项目时,我想总是在 master 以外的分支上进行编辑。 Master 用于工作的、经过测试的代码。
我有时会忘记这一点,并开始在 master 分支上编码。然后我必须重置更改等。
我想知道有什么方法可以使主文件只读,但仍然允许 merge 到其中。
最佳答案
您可以添加一个预提交钩子(Hook)( like this gist ,它可以阻止对 master 的意外提交)
你可以适应 hook to bypass it for merge commits .
VSCode 应该通过 Git 尊重预提交,如果您在 master
上,您将无法立即提交。 .
您需要存储,切换分支,存储流行音乐。
实际上,与new git switch
command (Git 2.23,2019 年 8 月),你甚至不必藏起来。
example section of git switch
处理您的场景(开始在“错误”分支上工作)
After working in the wrong branch, switching to the correct branch would be done using:
$ git switch mytopic
However, your "wrong" branch and correct "
mytopic
" branch may differ in files that you have modified locally, in which case the above switch would fail like this:
$ git switch mytopic
error: You have local changes to 'frotz'; not switching branches.
You can give the
-m
flag to the command, which would try a three-way merge:
$ git switch -m mytopic
Auto-merging frotz
关于git - Visual Studio Code/Git : Is there any way to prevent editing on master branch, 还允许 merge 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57566495/