Git: 保持所有分支都是最新的
Git: Keep all branches up to date
伙计们!
我最近在一家小公司获得了 DevOp 职位,我的第一个任务听起来是这样的:
Most usual scenario is that a dev works on a branch, then switches
branch to do a hotfix and forgets to do a git pull before making
changes or before creating a new branch off that particular branch.
我想知道我怎样才能达到这个目标,同步他们的工作,以防我们的一位开发者忘记使用 git pull
。
- 如果 Jenkins 可以帮助我们实现目标,我们就会使用它。
谢谢!
我想你要找的是 git 钩子
来自 GIT doc
Like many other Version Control Systems, Git has a way to fire off custom scripts when certain important actions occur. There are two groups of these hooks: client-side and server-side. Client-side hooks are triggered by operations such as committing and merging, while server-side hooks run on network operations such as receiving pushed commits. You can use these hooks for all sorts of reasons.
对于您的用例,我认为最好的方法是使用 post-checkout 钩子
所以当有人切换或结帐时,bash 脚本将 运行
要对此进行测试,请转到 git 文件夹并 运行
echo '#!/bin/sh' > .git/hooks/post-checkout
echo "echoed by git hook" >> .git/hooks/post-checkout
使文件可执行
chmod+x .git/hooks/post-checkout
然后尝试切换到一个分支,你会看到“echoed by git hook”的内容
伙计们! 我最近在一家小公司获得了 DevOp 职位,我的第一个任务听起来是这样的:
Most usual scenario is that a dev works on a branch, then switches branch to do a hotfix and forgets to do a git pull before making changes or before creating a new branch off that particular branch.
我想知道我怎样才能达到这个目标,同步他们的工作,以防我们的一位开发者忘记使用 git pull
。
- 如果 Jenkins 可以帮助我们实现目标,我们就会使用它。
谢谢!
我想你要找的是 git 钩子 来自 GIT doc
Like many other Version Control Systems, Git has a way to fire off custom scripts when certain important actions occur. There are two groups of these hooks: client-side and server-side. Client-side hooks are triggered by operations such as committing and merging, while server-side hooks run on network operations such as receiving pushed commits. You can use these hooks for all sorts of reasons.
对于您的用例,我认为最好的方法是使用 post-checkout 钩子
所以当有人切换或结帐时,bash 脚本将 运行
要对此进行测试,请转到 git 文件夹并 运行
echo '#!/bin/sh' > .git/hooks/post-checkout
echo "echoed by git hook" >> .git/hooks/post-checkout
使文件可执行
chmod+x .git/hooks/post-checkout
然后尝试切换到一个分支,你会看到“echoed by git hook”的内容