git实用命令总结

来源:互联网 发布:软件测评 编辑:程序博客网 时间:2024/05/17 05:13

从远程克隆仓库
git clone {gitaddress}

新建分支
git branch branchName

检出分支
git checkout branchName

把文件加到跟踪态
git add file

当前目录下所有文件加入
git add .

合并指定分支到当前分支
git merge fromBranchName

暂存
git stash

如果有部分文件不想commit,可以使用stash暂存
git stash –工作目录回到你上一次提交版本
git stash pop –将最后一次暂存的文件放回工作目录
git stash apply stash@{1} 就可以将你指定版本号为stash@{1}的工作取出来

与远程分支默认绑定,push与pull的时候不需要指定分支
git branch –set-upstream-to=origin/dev

如果不指定绑定的话,push与pull的时候需要
git push origin localBranch:remoteBranch
git pull

回滚提交文件到某一次版本
git reset 版本引用

取消pull操作
git reset –hard HEAD

检出远程分支到本地分支
git checkout -b localBranch origin/remoteBranch

更新分支信息到本地
git fetch

revert and reset
git revert 是撤销某次操作,此次操作之前的commit都会被保留
git reset 是撤销某次提交,但是此次之后的修改都会被退回到暂存区

具体一个例子,假设有三个commit, git st:
commit3: add test3.c
commit2: add test2.c
commit1: add test1.c

当执行git revert HEAD~1时, commit2被撤销了
git log可以看到:
commit1:add test1.c
commit3:add test3.c
git status 没有任何变化

如果换做执行git reset –soft(默认) HEAD~1后,运行git log
commit2: add test2.c
commit1: add test1.c

0 0
原创粉丝点击