git 命令
1. 需要指定某个版本的代码,不是最新的
1.1 首先
git pull
把代码更新到最新
1.2
git log
会出来:
commit 6c182f8c2a98665d73a92dd13127503e9f0289c1
Author: hello hello@123.com.cn
Date: Tue Jan 21 16:43:03 2020 +0800
ignore
commit 268976392e0935b4524f287935c1a16be9afc5d0
Author: hello hello@123.com.cn
Date: Tue Jan 21 16:22:27 2020 +0800
将base/utility合并,删除冗余
代码
commit 076bd5c5426a1c257343c98054d8cad582c079f1
Author: hello hello@123.com.cn
Date: Tue Jan 21 11:49:29 2020 +0800
代码精简
commit 9348818c3606e5ed80e4f63e2b657635dadd7711
Author: hello hello@123.com.cn
Date: Tue Jan 21 10:18:02 2020 +0800
1.3
git checkout 9348818c3606e5ed80e4f63e2b657635dadd7711
“9348818c3606e5ed80e4f63e2b657635dadd7711”就是上面某个commit id
会显示:
Note: checking out '9348818c3606e5ed80e4f63e2b657635dadd7711'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b
HEAD 目前位于 9348818...容错降为2
git branch -a # 检查有哪些分支?
git checkout v2.0 # 捡取v2.0分支进行编译
git tag -l -n // 列表&说明
下载最新代码,修改一些东西再推代码的时候,在此期间有人推了代码就会报错,解决方案:
当git push推代码的时候,出现提示如下:
To git@192.168.11.55:project_2020/project.git
! [rejected] master -> master (fetch first)
error: 无法推送一些引用到 'git@192.168.11.55:project_2020/project.git'
提示:更新被拒绝,因为远程仓库包含您本地尚不存在的提交。这通常是因为另外
提示:一个仓库已向该引用进行了推送。再次推送前,您可能需要先整合远程变更
提示:(如 'git pull ...')。
提示:详见 'git push --help' 中的 'Note about fast-forwards' 小节。
原因:由于在你拉的最新代码之后又有人提交代码了
解决:
step1:git pull --rebase origin master
会出现如下信息:
remote: Counting objects: 8, done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 8 (delta 6), reused 0 (delta 0)
展开对象中: 100% (8/8), 完成.
来自 192.168.11.55:project_2020/project
- branch master -> FETCH_HEAD
db1eec4..4d42914 master -> origin/master
首先,回退分支以便在上面重放您的工作...
应用:删除无用代码,整理合并
step2:git push origin master
对象计数中: 52, 完成.
Delta compression using up to 8 threads.
压缩对象中: 100% (52/52), 完成.
写入对象中: 100% (52/52), 8.67 KiB | 0 bytes/s, 完成.
Total 52 (delta 45), reused 0 (delta 0)
To git@192.168.11.55:project_2020/project.git
4d42914..91af53e master -> master