• Git 使用教程


    This blog is about the workflow of Git version control
    You are welcomed to chat about it and if you like this blog, do not forget to give me a like.
    
    • 1
    • 2

    Welcome to see my homepage and contact me: NicholasYe’s Homepage.


    Normal workflow

    1. Git clone and create a new branch

    1. use git clone {repo link} to download repo into local file, there are two kinds of links:
      1. ssh link(recommended): git@github.com:NicholasYe/xxxxxxxx.git
      2. https link: https://github.com/NicholasYe/xxxxxxxx.git
    2. enter the file, then normally you will find that you are in branch master
    3. use git checkout -b {Branch_Name} to create a new branch
      1. you can also use git checkout -b {Branch_Name} origin/{Branch_Name} to copy others branch

    2. Store and push changes in your new branch

    1. After switching to your new branch, you can write some codes you want
    2. use git add . to temporarily store your changes
    3. use git commit -m "{Comment}" to store your changes with some comments
    4. If you are the first time to push:
      1. use git push --set-upstream origin {Branch_Name} to push your local branch into remote branch origin/{Branch_Name}
      2. If not, just use git push to push your branch into remote branch
    5. Open github.com and you can create your new branch into PR

    3. Merge master changes into your branch

    1. use git checkout master to change to your master branch
    2. use git pull to update your master branch
    3. use git checkout {Branch_Name} to change to your branch
    4. use git merge master to merge master branch
    5. use git add . and git commit -m "{Comment}" and git push to push your branch

    Useful commands of Git

    1. Check your working history

    1. use git log to check your working history
    2. use git log --oneline to check your commit’s and comments in one line
    3. use git log --author={Author_Name} to check commit with specific author
    4. use git log -p to see detail changes of each commit
    5. use git log --stat to see summary of each commit

    2. Check your local and remote branch

    1. use git branch to check your local branch
    2. use git branch -r to check remote branch
    3. use git branch -a to check all the branch
    4. use git branch -D {Branch_Name} to delete one branch

    3. Revert or Reset your commit

    Notice: REVERT and RESET is totally different thing, be careful!

    revert: git revert will only undo only changes associated with a specific commit.
    reset: git reset will undo every changes since a given commit occurred.

    • Revert:
      1. use git revert {Commit_id} to revert changes of one commit
      2. use git revert HEAD~{Number} to revert to previous {number} commit. (I recommend you to use git log before to check where is HEAD now)
    • Reset:
      1. use git reset HEAD~{Number} to reset to previous {number} commit. (I recommend you to use git log before to check where is HEAD now)
      2. use git reset --soft {Commit_id} to reset all to this commit, and all the changes is stored in staged changes, use git commit -m "{comment}"
      3. use git reset --mixed {Commit_id} to reset all to this commit, and all the changes isn’t stored, use git add . and git commit -m "{comment}"
      4. use git reset --hard {Commit_id} to reset all to this commit. (Be careful when you use this)

    4. Cherry-pick forward commit

    Notice: With the cherry-pick command, Git allows you to integrate selected, individual commits from any branch into your current HEAD branch.

    1. use git cherry-pick {Commit_id} to cherry-pick specific commit in your current HEAD branch.
    2. use git cherry-pick {Commit_id} --no-commit to cherry-pick specific commit, then you need to use git commit -m {Comment} to commit

    Please clearly mark the source of the article in the process of reproducing it! Respect for originality and intellectual property rights, thanks!

  • 相关阅读:
    微信小程序 | 小程序开发
    Mysql批量插入更新如何拆分大事务?
    openGauss学习笔记-61 openGauss 数据库管理-常见主备部署方案
    (三)操作系统的运行环境
    使用nohup命令 或者 代码创建守护进程
    高级CSS属性实现的瀑布流的三种方法
    Android高版本读取沙盒目录apk解析安装失败解决方案
    MySQL读写分离原理
    Unity(第十九部)射线
    Go操作各大消息队列教程(RabbitMQ、Kafka)
  • 原文地址:https://blog.csdn.net/NicholasYTZ/article/details/126440911