Git Command

Collections

  • Remove all files to create an empty working directory

    1
    2
    3
    git rm -rf .
    git commit -a -m 'delete all files'
    git push origin gh-pages
  • Add content and push

    1
    2
    3
    4
    echo "My Page" > index.html
    git add index.html
    git commit -a -m "First pages commit"
    git push origin master
  • Deploying a subfolder to GitHub Pages

    1
    2
    3
    4
    git checkout master # you can avoid this line if you are in master...
    git subtree split --prefix dist -b gh-pages # create a local gh-pages branch containing the splitted output folder
    git push -f origin gh-pages:gh-pages # force the push of the gh-pages branch to the remote gh-pages branch at origin
    git branch -D gh-pages # delete the local gh-pages because you will need it: ref

Rebase

1
2
3
      C---D---E your_branch
/
A---B---F---G master

After rebase as following:

1
2
3
              C'--D'--E' your_branch
/
A---B---F---G master

Using rebase to solve below 2 issues:

  • This branch is out-of-date with the base branch

    Branch Conflicts

  • This branch has conflicts that must be resolved

    Branch Conflicts

Process Flow:

  1. git checkout master, and then git pull

  2. git checkout <your_branch>, if need, do git pull

  3. git rebase master

  4. Option step if there are CONFLICTs.

    1. change conflicts and save them

    2. git add <file_name> or git add .

      Note: do not need commit during fixing conflicts.

    3. git rebase --continue

    4. loop above if conflicts still existed.

  5. git push -u origin <your_branch> --force

Reset

Resetting remote to a certain commit

Assuming that your branch is called master both here and remotely, and that your remote is called origin you could do:

  1. git checkout <your_branch>
  2. git log , find the commit-hash
  3. git reset <commit-hash> , undoes all commits after [commit]4
  4. git push -f origin <your_branch>

Note:

  • git remote -v to get remote information
  • git log --pretty=oneline or git log -2 to show version history

Cherry pick

  1. git checkout <the_branch_contains_that_commit>
  2. git log --oneline -3 find the commit id
  3. git checkout <your_branch>
  4. git cherry-pick <commit> -n –no-commit
  5. commit by yourself.
感谢支持,让我安静的做蚂蚁梦!