制作补丁

你发现了一个bug或者其他你想改变的东西 Matplotlib … — 杰出的!

你已经找到了解决问题的方法 — 甚至更好!

你想告诉我们 — 最好的!

最简单的方法是 补丁 或一组补丁。在这里我们解释如何。做一个补丁是最简单和最快的,但是如果你要做的不仅仅是简单的快速的事情,请考虑遵循 用于开发的Git 模型代替。

制作补丁

概述

# tell git who you are
git config --global user.email you@yourdomain.example.com
git config --global user.name "Your Name Comes Here"
# get the repository if you don't have it
git clone git://github.com/matplotlib/matplotlib.git
# make a branch for your patching
cd matplotlib
git branch the-fix-im-thinking-of
git checkout the-fix-im-thinking-of
# hack, hack, hack
# Tell git about any new files you've made
git add somewhere/tests/test_my_bug.py
# commit work in progress as you go
git commit -am 'BF - added tests for Funny bug'
# hack hack, hack
git commit -am 'BF - added fix for Funny bug'
# make the patch files
git format-patch -M -C master

然后,将生成的补丁文件发送到 Matplotlib mailing list — 在那里我们将热烈地感谢你。

详细地

  1. 告诉Git你是谁,这样它就可以标记你所做的承诺:

    git config --global user.email you@yourdomain.example.com
    git config --global user.name "Your Name Comes Here"
    
  2. 如果您还没有,请克隆 Matplotlib 储存库:

    git clone git://github.com/matplotlib/matplotlib.git
    cd matplotlib
    
  3. 制作一个“功能分支”。这将是您修复bug的地方。它很好而且安全,让您可以访问主分支中未修改的代码副本:

    git branch the-fix-im-thinking-of
    git checkout the-fix-im-thinking-of
    
  4. 进行一些编辑,并在执行过程中提交它们:

    # hack, hack, hack
    # Tell git about any new files you've made
    git add somewhere/tests/test_my_bug.py
    # commit work in progress as you go
    git commit -am 'BF - added tests for Funny bug'
    # hack hack, hack
    git commit -am 'BF - added fix for Funny bug'
    

    注意 -am 选项到 commit . 这个 m 标志只是表示您要在命令行上键入消息。这个 a 旗帜 — 你只要有信心 — 或看到 why the -a flag? .

  5. 完成后,检查是否已提交所有更改::

    git status
    
  6. 最后,将您的提交提交到补丁中。你想要所有的承诺,因为你从 master 分支机构:

    git format-patch -M -C master
    

    现在,您将有几个为提交命名的文件:

    0001-BF-added-tests-for-Funny-bug.patch
    0002-BF-added-fix-for-Funny-bug.patch
    

    将这些文件发送到 Matplotlib mailing list .

完成后,要切换回代码的主副本,只需返回到 master 分支机构:

git checkout master

从修补到开发

如果您发现已经完成了一些补丁,并且您有一个或多个功能分支,那么您可能需要切换到开发模式。您可以使用您拥有的存储库来完成此操作。

Matplotlib Github上的存储库 — 制作你自己的Matplotlib拷贝(fork) . 然后:

# checkout and refresh master branch from main repo
git checkout master
git pull origin master
# rename pointer to main repository to 'upstream'
git remote rename origin upstream
# point your repo to default read / write to your fork on github
git remote add origin git@github.com:your-user-name/matplotlib.git
# push up any branches you've made and want to keep
git push origin the-fix-im-thinking-of

然后,如果您愿意,可以按照 开发工作流 .