向GitHub开源项目贡献代码
2020-01-14 18:19
369 查看
原英文版: Contribute to repositories on GitHub
向Github开源项目贡献代码
前言
以最近接触的测试开源项目Robottelo为例,整理向GitHub开源项目贡献代码的步骤、方法及注意事项,备查,未完待续…
Git配置
- 创建SSH key
$ ssh-keygen -t rsa -C "youremail@example.com" cat ~/.ssh/id_rsa.pub
- 登陆GitHub页面 -> Account Settings -> SSH and GPG Keys -> SSH keys -> New SSH key -> Add SSH key,创建SSH key
- 配置 username and email
$ git config user.name “username” $ git config user.email “username@emil.con” $ git config --list
创建Env环境
- 克隆仓库
git clone git@github.com:SatelliteQE/airgun.git
- 创建独立的env环境(避免与本机当前的环境产生冲突)
virtualenv --no-site-packages venv source venv/bin/activate (venv) $
贡献代码
复刻仓库
- 查看remote的仓库
(master) $ git remote -v origin git@github.com:hkx303/robottelo.git (fetch) origin git@github.com:hkx303/robottelo.git (push)
- 将Robottelo作为远程仓库
(master) $ git remote add upstream git@github.com:SatelliteQE/robottelo.git
- 检查remote仓库
(master) $ git remote -v origin git@github.com:hkx303/robottelo.git (fetch) origin git@github.com:hkx303/robottelo.git (push)upstream git@github.com:SatelliteQE/robottelo.git (fetch) upstream git@github.com:SatelliteQE/robottelo.git (push)
- 拉取最新的upstream的代码
(master) $ git fetch upstream
- 变基:复刻的master分支的代码 将分支历史并入upstream主线
(master) $ git rebase upstream/master
创建分支
- 在本地创建分支
(master) $ git checkout -b branch_name
或
(master) $ git branch branch_name (master) $ git checkout branch_name
- 查看更改情况
(branch_name) $ git status (branch_name) $ git diff
- 在本地仓库中提交代码,更新详细的提交信息
(branch_name) $ git add <all modified or new files> (branch_name) $ git commit Add more information about what the entire commit is about.
提交代码
- 使用 pycodestyle-3工具来检查代码风格
pip install pycodestyle-3
- 检查代码
pycodestyle-3 --show-source --first <filename>
- 提交代码
(branch_name) $ git push origin branch_name
- 通过github的链接提交申请
更新提交申请
- 更新提交申请
(branch_name) $ pycodestyle-3 --show-source --first <filename>(branch_name) $ git add <files> (branch_name) & git commit -m "messages" (branch_name) $ git push origin branch_name
无法合并
- 使自身的master分支与上游分支同步
(branch_name) $ git checkout master (master) $ git fetch upstream(master) $ git rebase upstream/master(master) $ git push
- 使我们的工作目录与master分支同步
(master) $ git checkout branch_name (branch_name) $ git rebase master
- 提交分支
(branch_name) $ git push origin branch_name
- 提交时提示commit历史被修改——使用force
(branch_name) $ git push origin branch_name --force
撤销提交
- 已经更改文件但需要恢复这些更改,并且不需要保留更改
(branch_name) $ git checkout -- FILE
- 已经更改文件,运行了 git add FILE 命令,但想要恢复,同时需要保留所做的更改
(branch_name) $ git reset HEAD FILE
- 已经做出更改,且commit了所有的更改,但想要恢复: 需要保留所作的更改
(branch_name) $ git reset --soft HEAD~
- 不需要保留所作的更改
(branch_name) $ git reset --hard HEAD~
注意: HEAD~ 代表最后一次commit。如果想要恢复最近的3次commit,把HEAD~ 更改为 HEAD~3.
Git的其他命令
查看历史
- 查看git提交历史
git log
- 查看git提交历史,减少输出信息
git reflog
- 查看git历史命令
git reflog
- 查看git分支图表
git log --graph
关于分支
- 合并指定分支至当前分支
git merge <branch_name>
- 删除分支
git branch -d <branch_name>
Git remove
$ git rm test.txt rm 'test.txt' $ git commit -m "remove test.txt"
Git stash
- 把当前工作现场“储藏”起来,等以后恢复现场后继续工作:
$ git stash
- 查看stash列表
$ git stash list
- 恢复,不删除stash内容
$ git stash apply
- 恢复的同时删除stash内容
$ git stash pop
- 恢复指定的stash
$ git stash apply stash@{0}
cherry-pick
- 复制一个特定的提交到当前分支
$ git cherry-pick 4c805e2
参考资料
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- 零基础学习GitHub桌面版-4 怎么给开源项目贡献代码?
- 如何在Github上为开源项目贡献自己的代码
- github,怎么向开源项目贡献自己的代码和协作
- github,怎么向开源项目贡献自己的代码和协作
- 如何在github上发起一个pull request,如何贡献代码,参与开源项目
- 如何在github上发起一个pull request,如何贡献代码,参与开源项目
- 番外:如何给github上的开源项目贡献代码?
- 在github上参与开源项目贡献代码
- 如何在github上fork一个项目来贡献代码以及同步原作者的修改
- [GitHub]第六讲:开源项目贡献流程
- (转)大白话讲解如何给github上项目贡献代码
- 【转】如何在GitHub上fork一个项目来贡献代码以及同步原作者的修改
- github发布开源项目代码教程
- github发布开源项目代码教程
- Github网站加载不完全,响应超时,如何解决 Github是一个代码托管平台和开发者社区,开发者可以在Github上创建自己的开源项目并与其他开发者协作编码。毫不夸张地说,高效利用Github是一
- 如何在github上fork一个项目来贡献代码以及同步原作者的修改
- 主要通过你的行为看你的编程能力,除了让你做算法题外,更重要的是你实际写过的代码和项目,效率如何?有没有考虑过异常处理?实际的访问性能如何?有没有开过自己的 github 项目,或者是给知名项目贡献过源
- 花20分钟写的-大白话讲解如何给github上项目贡献代码(转)
- android studio 倒入github开源项目代码步骤:
- 如何在开源项目中贡献代码