Git的基本命令及其他—笔记

git add 添加修改

git add . 添加所有修改
git add -u 添加修改过的部分(不包含untracked的)
git add -i 互动添加模式

git commit 提交修改

git commit -m {commit message} 单行提交
git commit - -amend 编辑上一次的commit信息

git pull 从远程更新本地代码

git pull origin master 从远程端口origin的master分支更新到本地

git push 从本地更新远程代码

git push origin master 更新到远程端口origin的master分支上
git push remote {yourbranch:master} 更新到你的分支到remote的master上

git reset 撤回提交

git reset 放弃add,但保留修改
git reset - -hard 放弃所有修改,回到上一次commit的状态
git reset - -hard HEAD 回到最新一次commit的状态
git reset - -hard HEAD^ 回到前一个commit的版本
git reset - -hard HEAD^^ 回到前两次的commit版本
git reset - -hard HEAD~2 回到前三的commit的版本
git reset - -soft HEAD 回到commit提交前的状态

git branch 分支

git branch 列出所有分支
git branch {new-branch} 在此branch上建新的branch
git branch {new-branch} master 从master上建新的branch
git branch push -u origin {new-branch} 建立远端branch
git branch -a 显示所有branch (包含remote)
git push origin :branch 删除远端的branch

git checkout 切换分支

git checkout {branch-name} 切换到branch-name分支
git checkout master 切换到master
git checkout -b {new-branch} master 从master上建立新的分支
git checkout -b {new-local-branch-name} origin/{branch-name} 建立来自remote的分支
git checkout - - {file-name} 放弃提交前的修改

git log

git log 将列出所有的log
git log - -graph - -oneline - -all 展出提交示意图

git tag

git tag -l 列出所有的tag
git tag -a {tag-name} -m “tag-message” 在目前的HEAD建立tag-name的tag,并建立tag-messagede的信息
git tag {tag-name} commit-id 再commit-id的HEAD, 建立tag-name的tag

删除远程的分支和本地的分支

git branch origin –delete {the-remote-branch}
git branch -d {the-local-branch}

git的基本设置

生成sshkey:
ssh-keygen -t rsa -C “email_address”
git的配置:
git config - -global user.name “your_name”
git config - -global user.email “your_email_address”

2

猜你喜欢

转载自blog.csdn.net/lulongfei172006/article/details/78358386
今日推荐