• 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!

  • 相关阅读:
    [语音识别] 基于Python构建简易的音频录制与语音识别应用
    python的opencv操作记录(五) - 空间域与频域转换
    【Android 屏幕适配】屏幕适配通用解决方案 ④ ( 自定义组件解决方案 | 计算设计稿与实际布局的比例系数 )
    安卓讲课笔记5.4 单选按钮和复选框
    Hystrix:断路器
    linux后台开发面试题
    JS有哪些基本数据类型,它们的区别?
    9面阿里Java岗,最终定级P6拿P7工资,分享学习经验
    新超导光子电路
    【HTML专栏3】!DOCTYPE、lang、字符集的作用
  • 原文地址:https://blog.csdn.net/NicholasYTZ/article/details/126440911