Q&A about git

Q: How to quickly undo the changes in the repo?

A:

  git reset --hard master@{"10 minutes ago"}

  git push -f origin master

Q: How to contribute to open source project?

A: Pull Request

 

Q: How to do a pull request?
A: 

  1. fork the repo.

      2. git clone a.git

      3. git remote add upstream a.git

      4. git checkout -b branchname

      5. coding

      6. git add . && git commit -m “change”      

      7. git push origin branchname

      8. start a pull request in github

 

Q: Update a forked repository?

A:

     1. git remote add upstream ["Original github repository"]

     2. git fetch upstream

     3. git checkout master

     4. git rebase upstream/master

     5. git push -f origin master

Link: https://stackoverflow.com/questions/7244321/how-do-i-update-a-github-forked-repository

 

Q: How to squash some commits into one commit?

A: git rebase -i SHA-1

    git push -f

Q: How to squash last three commits into one commit?

A: git rebase -i HEAD~3 

    git push -f

 

Q: What if we start a pull request from master but we want to do another pr before the previous pr is merged?

A:

     git checkout master

     git pull --rebase upstream master

     git checkout -b newbranch

     coding

     git push origin newbranch   

     git checkout master 

     git reset --hard

   git push -f origin master

 

Q: How to update the last commit?

A: git commit . --amend

    git push -f origin HEAD

 

Q: How to update the branch for the pull request?

A: 

    git checkout master

    git pull --rebase upstream master

    git push -f

    git checkout branchname

    git rebase master

    git push -f      

Q: How to remove commit that has not been pushed?

A:

     git reset --hard HEAD^

     git reset --hard origin/master

Q: How to discard change before commit?

A:

     git stash

     git stash drop 

 

posted @ 2017-02-11 16:06  Yuchi1989  阅读(141)  评论(0)    收藏  举报