git常用命令详解

来源:互联网 发布:淘宝宾卡达手表怎么样 编辑:程序博客网 时间:2024/06/02 12:12
  1. 克隆代码库
    • git clone
  2. 初始化代码库
    • git init
  3. 查看分支状态
    • git branch
  4. 比较代码不同
    • git diff
  5. 向代码库添加代码
    • git add
  6. 向代码库提交代码
    • git commit
  7. 把本地代码推到远程主机上

    • git push

    git push 默认将当前分支推送到remote的同名分支上,如果只输入 git push origin 则会提示warning:

    warning: push.default is unset; its implicit value is changing in
    Git 2.0 from ‘matching’ to ‘simple’. To squelch this message
    and maintain the current behavior after the default changes, use:

    git config –global push.default matching

    To squelch this message and adopt the new behavior now, use:

    git config –global push.default simple

    When push.default is set to ‘matching’, git will push local branches
    to the remote branches that already exist with the same name.

    In Git 2.0, Git will default to the more conservative ‘simple’
    behavior, which only pushes the current branch to the corresponding
    remote branch that ‘git pull’ uses to update the current branch.

    See ‘git help config’ and search for ‘push.default’ for further information.
    (the ‘simple’ mode was introduced in Git 1.7.11. Use the similar mode
    ‘current’ instead of ‘simple’ if you sometimes use older versions of Git)

    所以在使用git push 的时候,要么使用origin 并指明分支,要么不使用origin

  8. 更新远程主机代码到本地

    • git pull
  9. 合并代码
    • git merge
    • git rebase
    • git cherry-pick
  10. 查看日志
    • git log
0 0
原创粉丝点击