我是靠谱客的博主 爱撒娇马里奥,最近开发中收集的这篇文章主要介绍Contribute to repositories on GitHubAboutGit configCreate EnvContribut to GitHubOther usages for GitReference,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

Contribute to repositories on GitHub

  • About
  • Git config
  • Create Env
  • Contribut to GitHub
    • Fork it
    • Branch it before you work
    • Push it
    • Updating a Pull Request
    • PR cannot be merged
    • Undo my commit
  • Other usages for Git
    • Show history
    • Branch
    • Git remove
    • Git stash
    • cherry-pick
  • Reference

About

  • Take Robottlo repo as an example, introduce the steps for contributing to repositories on Github

Git config

  • Create SSH key
    $ ssh-keygen -t rsa -C "youremail@example.com"
    cat ~/.ssh/id_rsa.pub
    
  • Login GitHub > Account Settings > SSH and GPG Keys > SSH keys > New SSH key > Add SSH key
  • Config username and email
    $ git config user.name “username”
    $ git config user.email “username@emil.con”
    $ git config --list
    

Create Env

  • Clone the repositories
git clone git://github.com/SatelliteQE/robottelo.git
  • Create a independent env
virtualenv venv
source venv/bin/activate
(venv) $

Contribut to GitHub

Fork it

  • Show remote repositories
(master) $ git remote -v
origin	git@github.com:hkx303/robottelo.git (fetch)
origin	git@github.com:hkx303/robottelo.git (push)
  • Add Robottelo as a remote repository to your fork
(master) $ git remote add upstream git@github.com:SatelliteQE/robottelo.git
  • check it again
(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)
  • Fetch latest upstream code
(master) $ git fetch upstream
  • Rebase your fork’s master repo to match upstream’s
(master) $ git rebase upstream/master

Branch it before you work

  • Create new local repo to work on issue or feature
(master) $ git checkout -b branch_name

or

(master) $ git branch branch_name   
(master) $ git checkout branch_name
  • Show your changes
(branch_name) $ git status
(branch_name) $ git diff
  • Make all your changes in the local branch_name repo and commit with a nice, short subject and a detailed message
(branch_name) $ git add <all modified or new files>
(branch_name) $ git commit

 Add more information about what the entire commit is about.

Push it

  • use pycodestyle-3 to check the code style
    pip install pycodestyle-3
    
  • check code
    pycodestyle-3 --show-source --first <filename>
    
  • Push your changes for a PR
    (branch_name) $ git push origin branch_name
    
  • Create a Pull Request through the github link

Updating a Pull Request

  • Need to make more changes either because you received feedback for your PR or because you’re not done yet?
    (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
    

PR cannot be merged

  • First, let’s rebase your master to reflect upstream’s master
    (branch_name) $ git checkout master
    (master) $ git fetch upstream
    (master) $ git rebase upstream/master
    (master) $ git push
    
  • Now, let’s rebase our working directory against your master
    (master) $ git checkout branch_name
    (branch_name) $ git rebase master
    
  • Push your rebased branch_name back to Github
    (branch_name) $ git push origin branch_name
    
  • Git complaining about rebase because commit history is being changed? Use the --force Luke
    (branch_name) $ git push origin branch_name --force
    

Undo my commit

  • So you made changes to FILE but you changed your mind and want to revert your changes? Don’t want to preserve your changes either?
    (branch_name) $ git checkout -- FILE
    
  • So you made changes to FILE, ran git add FILE but you changed your mind and want to revert your changes? Want to preserve your changes?
    (branch_name) $ git reset HEAD FILE
    
  • So you went ahead and committed your changes and everything is ‘staged’, but you changed your mind and want to ‘unstage’ it?
    • If you want to preserve your changes so that you can continue working on them:
    (branch_name) $ git reset --soft HEAD~
    
    • If you don’t want to preserve your changes:
    (branch_name) $ git reset --hard HEAD~
    

NOTE: Please note that HEAD~ represents ‘the last commit’. If you want to undo the last 3 commits, then change HEAD~ to HEAD~3.

Other usages for Git

Show history

  • Show git history
    git log
    
  • Show git history and reduce output messages
    git reflog
    
  • Show git history command
    git reflog
    
  • Show git branch graph
    git log --graph
    

Branch

  • Merge branch to current branch
    git merge <branch_name>
    
  • Delete branch
    git branch -d <branch_name>
    

Git remove

$ git rm test.txt
rm 'test.txt'

$ git commit -m "remove test.txt"

Git stash

  • Stash the changes in a dirty working directory away
    $ git stash
    
  • Check stash list
    $ git stash list
    
  • Restore the stash and do not delete it
    $  git stash apply
    
  • Restore the stash and delete it
    $ git stash pop
    
  • Restore the expected stash
    $ git stash apply stash@{0}
    

cherry-pick

  • Copy commit to current branch
    $ git cherry-pick 4c805e2
    

Reference

How To Contribute

最后

以上就是爱撒娇马里奥为你收集整理的Contribute to repositories on GitHubAboutGit configCreate EnvContribut to GitHubOther usages for GitReference的全部内容,希望文章能够帮你解决Contribute to repositories on GitHubAboutGit configCreate EnvContribut to GitHubOther usages for GitReference所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(50)

评论列表共有 0 条评论

立即
投稿
返回
顶部