1.基本命令

  1. # 初始化本地仓库
  2. git init
  3. # 查看指定文件状态
  4. git status [file]
  5. # 查看所有文件状态
  6. git status
  7. # 将文件添加到暂存区(stage)
  8. git add .
  9. # 撤销提交
  10. git reset HEAD .
  11. # 提交代码
  12. git commit -m "new file hello.txt"
  13. # 在本地新建一个与远程的ysl版本相同(被合并的版本)的ysl分支
  14. git checkout -b ysl-local origin/ysl
  15. # 切换至master
  16. git checkout master
  17. # 把本地的ysl-local合并到master
  18. git merge ysl-local
  19. # 在当前分支下创建my-test的本地分支分支
  20. git checkout -b my-test
  21. # 将my-test分支推送到远程
  22. git push origin my-test
  23. # 将本地分支my-test关联到远程分支my-test上
  24. git branch --set-upstream-to=origin/my-test
  25. # 查看远程分支
  26. git branch -a
  27. # 删除本地分支
  28. git branch -d branch_name
  29. # 删除远程分支
  30. git branch -r -d origin/branch-name
  31. # 撤销分支合并
  32. git merge --abort
  33. # 查看分支关联情况
  34. git branch -vv
  35. # 已关联的远程分支,重新绑定另外的远程分支
  36. git push --set-upstream origin overseas-feature-google

如下截图详情

image.png

2. 忽略文件.gitignore

  1. HELP.md
  2. target/
  3. !.mvn/wrapper/maven-wrapper.jar
  4. !**/src/main/**/target/
  5. !**/src/test/**/target/
  6. ### STS ###
  7. .apt_generated
  8. .classpath
  9. .factorypath
  10. .project
  11. .settings
  12. .springBeans
  13. .sts4-cache
  14. ### IntelliJ IDEA ###
  15. .idea
  16. *.iws
  17. *.iml
  18. *.ipr
  19. ### NetBeans ###
  20. /nbproject/private/
  21. /nbbuild/
  22. /dist/
  23. /nbdist/
  24. /.nb-gradle/
  25. build/
  26. !**/src/main/**/build/
  27. !**/src/test/**/build/
  28. ### VS Code ###
  29. .vscode/

3.配置SSH公钥免登录
windows下C:\Users\HUAWEI.ssh
ssh-keygen -t rsa
image.png

3.版本回退

1.回退到上一个版本

  1. git reset --hard HEAD^
  2. # 会提示 More? 因为我们只要到上一个版本所以我们输入:^
  3. # 本地的回滚成功了,但是远程的依然还是新版本的,所以我们需要强制提交一下
  4. git push -f