Common git commands

Source: Internet
Author: User
Tags git commands

Basis
# 初始化仓库git init 
# 从工作区添加到暂存区git add 1.c
# 查看当前状态git status
# 暂存区提交到仓库git commit -m ‘add 1.c‘ # 与远程仓库建立联系git remote add origin https://git.coding.net/userName/repName.git
# 提交到远程分支git push -u origin master
# 拷贝到本地git clone git checkout -b dev origin/dev

<!--more--

Changes and versions
# 查看文件改动git diff 1.c     
reset --hard HEAD^
# git历史命令git reflog
# 历史提交信息git log
# 指定id,退回未来版本git reset --hard commit_id
# 查看与仓库最近一次更改变化git diff HEAD --1.c
# 撤销更改,(还没有addgit checkout --1.c
# 从暂存区退回,(取消addgit reset HEAD 1.c git push origin master
Branch
# 创建并切换到分支git checkout -b dev    
# 创建分支git branch d2
# 切换分支git checkout d2
# 查看所有分支git branch
# 删除分支git branch -d dev
# 强制删除分支git branch -D de
# 合并分支git merge dev git merge --no-ff -m ‘merge no ff‘ dev
# 分支合并图git log --graph
# push到对应分支git push origin :dev
Save site
# 保存现场git stash
# 查看已经保存的列表git stash list
# 恢复某个现场git stash apply stash@{0}
# 删除指定的现场git stash drop stash@{0}
# 取得并恢复栈顶的现场,且删除它git stash pop

原文地址

Common git commands

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.