Git使用笔记

1. git clone

  git clone http://example.com/test.git,按照提示输入账号密码即可

2. 第一步clone下来的可能只有master分支,想切换并下载其他分支怎么办?

  方法一:直接git checkout 分支,先git branch -r查看远程分支,然后git checkout 分支

3. git status: 查看状态,如修改内容后可以看到什么文件什么地方做了修改

4. git stash: 备份当前的工作区的内容,从最近的一次提交中读取相关内容,让工作区保证和上次提交的内容一致。同时,将当前的工作区内容保存到Git栈中。

  如果误用stash了,想将内容恢复,可以用git stash pop将栈中内容恢复出来

5. 配置git账号,在git stash/commit时可能提示需要配置账号

  git config --global user.name "your name"  

  git config --global user.email "your_email@youremail.com"  

  这个user name会显示在commit的用户名,不一定是你用的github账号名

6. 提交,上传

  git add:添加新文件

  push前需要commit:git commit -m "first commit"  

  git push origin master  

7. 查看commit log:

  git reflog 或者git log, git log内容更全面

8. 本地回退版本

  git reset --hard 12jhh4

  12jhh4是回退的版本的commit id

9. 自己的远程仓库回退

  与本地一致git reset --hard 12jhh4

  然后强制推送git push -f

10. 远程公共分支版本回退方法

  git revert 0ff12sa   //撤销0ff12sa这次提交

  如果有代码冲突,解决掉后新commit 然后提交

posted @ 2018-01-11 14:52  云无迹  阅读(118)  评论(0)    收藏  举报