我建立了一个名为project_name/.git的git源代码库。
ssh to the server, (entering ssh passwords or passphrases as I go)
mkdir project_name
cd project_name
git init
touch fabfile.py
git add fabfile.py
git commit -a -m "almost empty"
git checkout -b web
我离开分支网站签出。回到本地机器。
我从服务器通过克隆拉,并添加了我的项目目录在本地回购分公司主分支。尽管这些步骤也可以自动化,但我并不想使用结构,只是设置了一些东西,而且没有一个需要另一个SSH密码。
cd /path/to/project_name/..
git clone ssh://[email protected]_server.com/var/web/project_name/.git
cd project_name
gvim fabfile.py
git add fabfile.py
git commit -a -m "fabfile edits"
现在我开始使用fabric。下面是我的fabfile摘录管理Git标签 和分支:
#Usage: fab committag brpush | fab committag push | fab push | fab tag
def committag():
"""commit chgs, tag new commit, push tags to server."""
prompt('commit descr: ', 'COM_MSG', default='new stuff')
prompt('commit name: ', 'COM_NAME', default='0.0.1')
local('git commit -a -m "%(COM_MSG)s"' % env)
local('sleep 1')
local('git tag -u "John Griessen" -m "%(COM_MSG)s" %(COM_NAME)s' % env)
local('sleep 1')
local('git push origin --tags') #pushes local tags
def brpush():
"""create a new branch, default COM_NAME, then push to server."""
prompt('new branch name: ', 'BR_NAME', default= '%(COM_NAME)s' % env)
local('git checkout -b %(BR_NAME)s' % env)
local('sleep 2')
local('git checkout master')
local('git push origin --tags') #pushes local tags
local('git push --all origin') #pushes local master and branches
def push():
"""Push existing tags and changes to server."""
local('git push origin --tags') #pushes local tags
local('git push --all origin') #pushes local master and branches
def tag(): #Call this from committag()
"""create a gpg signed tag on the local git repo tag from prompted name ."""
prompt('tag descr: ', 'TAG_MSG', default='0.0.1')
prompt('tag name: ', 'TAG_NAME', default='0.0.1')
local('git tag -u "John Griessen" -m "%(TAG_MSG)s" %(TAG_NAME)s' % env)
使用上述fabfile DEFS,我只是做一些改变我的项目目录, 想着它们的apporpriate消息,并做:
$fab committag
我在服务器上标记和更新了更改。或者:
$fab committag brpush
我创建了一个新分支并更新了服务器。
可能重复[如何回答以自动提示与python结构?](http://stackoverflow.com/questions/10479078/how-to-answer-to-prompts-automatically-与蟒蛇织物) – Breedly 2017-02-05 15:11:57