本文已参与[新人创造礼]活动,一起开启掘金创作之路。 工作中遇到的常用命令总结
git log <!--查看提交历史-->
git reflog <!--查看命令历史,以便确定要回到未来的哪个版本-->
git log --graph 查看分支合并图
git reset --hard commitId <!--回退到指定的版本-->
git reset --hard ^HEAD <!--回退到上一个版本-->
git checkout --filename <!--文件在工作区的修改全部撤销-->
git reset HEAD filename <!--把暂存区的修改撤销掉,重新放回工作区-->
git rm filename => git commit <!--git 删除文件-->
误删除的时候 git checkout --filename
<!--将本地仓库推送到远程 start-->
git remote add origin git@github.com:XXX/repositoryname.git
<!--本地库的内容推送到远程-->
git push -u origin master
<!--由于远程库是空的,我们第一次推送master分支时,加上了-u参数,Git不但会把本地的master分支内容推送的远程新的master分支,还会把本地的master分支和远程的master分支关联起来,在以后的推送或者拉取时就可以简化命令。-->
<!--将本地仓库推送到远程 end-->
<!--远程克隆一个仓库到本地-->
git clone git@github.com:michaelliao/gitskills.git
git checkout -b branchname <!--创建分支并切换到branchname,实际执行如下操作:
git branch branchname
git checkout branchname-->
git branch 查看分支
git branch name 创建分支
git checkout branchname /git switch branchname 切换分支
git checkout -b branchname/ git swtich -c branchname 创建并切换到新分支
git merge branchname 合并分支到当前分支
git merge --no-ff -m '提交的描述' branchname 普通模式合并,合并后的历史有分支,能看出来曾经做过合并
git branch -d branchname 删除本地分支
git branch -D branchname 强行删除一个未合并的分支
git push origin -d filename 删除远程分支
git stash 把现场储存起来
git stash save ''
git stash apply stash@{1}
git stash list 查看储藏的工作区内容
恢复工作区的方法
方法一:
1、git stash apply 恢复 多次stash 恢复指定的stash git stash apply stash@{0}
2、git statsh drop 删除
方法二:
1、git stash pop
git cherry-pick commitid 复制一个特定的提交到当前分支
git remote 查看远程分支
git remote -v 显示更详细的信息
git pull 远程拉取分支
git push origin branchname 推送branchname 分支到远程库
git checkout -b branchname origin/branchname 在本地创建和远程分支对应的分支
git branch --set-upstream branchname origin/branchname
git commit --amend -m 'sdfsd' --amend修补参数会将改变之前的Commit ID,但不会生成新的Commit ID。
git branch -m [old_br] [new_br] 分支重命名
\