前言
将用到的github指令记录下来,持续更新,方便随时查找学习。
github_6">一、github用到的指令
1、我们从github克隆下来的代码版本一般都是master主分支,我们要建立自己的分支进行修改:
//git branch //查看目前的分支/*
* master //只要主分支
*/git branch users/cgf/feature_for_test /#建立新的分支git checkout users/cgf/feature_for_test //切换到新的分支git fetch ///将代码从master分支切换到新的分支git pull ///将代码从master分支切换到新的分支git branch //查看分支,发现有俩个分支了/*master
* users/cgf/feature_for_test
*/
2、比如在main函数里面增加一个打印,然后进行查看,将改动的代码上传到新的版本上,说一下修改了什么,最后把代码从本地分支推到远程github上。
//git status //查看修改了哪些.cpp文件/*修改: main.cpp*/git add main.cpp //将修改的代码保存到本地分支git commit -m "Add printing" //告诉修改了哪里git push --set-upstream origin users/cgf/feature_for_test //同步到github上
3、git log 查看刚刚的评论
git log
/*
commit 775d4ce10d3aaedf00af9b05968d5e18402a920b (HEAD -> users/cgf/feature_for_test, origin/users/cgf/feature_for_test)
Author: CGF <872980563@qq.com>
Date: Sun Jun 16 21:29:54 2024 +0800version 1.0*/
4、删除本地分支、上传github上的分支
git checkout master //先切换到其他分支git branch -d users/cgf/feature_for_test //删除刚刚建立的feature_for_test本地分支/*
warning: 将要删除的分支 'users/cgf/feature_for_test' 已经被合并到'refs/remotes/origin/users/cgf/feature_for_test',但未合并到 HEAD。
已删除分支 users/cgf/feature_for_test(曾为 775d4ce)。
*/git push -d origin users/cgf/feature_for_test //删除github上的分支git push origin -d users/cgf/feature_for_test //这样好像也可以/*
To github.com:shaoudelaochao/ImuAlignment.git- [deleted] users/cgf/feature_for_test
*/
5、 git commit --amend:修改最新的commit评论;git push -f origin users/cgf/feature_for_test:推送到github上,如下:
/*
commit 98b9b8911c8ba453e6e5b22b43aed5966d074051 (HEAD -> users/cgf/feature_for_test_1, origin/users/cgf/feature_for_test_1)
Author: CGF <872980563@qq.com>
Date: Sun Jun 16 22:10:24 2024 +0800version 3.0 //修改前的log日志*/git commit --amend //修改最新的commit/*
[users/cgf/feature_for_test_1 1646c5d] version 3.0 for testDate: Sun Jun 16 22:10:24 2024 +08001 file changed, 1 insertion(+), 1 deletion(-)
caiganfei@caiganfei-WEI6-14-IML:~/github_test/learngit/ImuAlignment/ImuAlignment$ git log
commit 1646c5ddfb3cb24d48e8b51f7738b16863fe3a4b (HEAD -> users/cgf/feature_for_test_1)
Author: CGF <872980563@qq.com>
Date: Sun Jun 16 22:10:24 2024 +0800version 3.0 for test //修改后的log日志
*/git push -f origin users/cgf/feature_for_test //将修改的commit推送到github上git rebase -i HEAD~3 //将3个commit合并到一起/*
pick 4b49d4f version 1.0
s 44694b0 version 2.0 for test
s 27e3a73 version 3.0 for test# 变基 3c21492..27e3a73 到 3c21492(3 个提交)
#
# 命令:
# p, pick = 使用提交
# r, reword = 使用提交,但修改提交说明
# e, edit = 使用提交,但停止以便进行提交修补
# s, squash = 使用提交,但和前一个版本融合
# f, fixup = 类似于 "squash",但丢弃提交说明日志
# x, exec = 使用 shell 运行命令(此行剩余部分)
# d, drop = 删除提交
#
# 这些行可以被重新排序;它们会被从上至下地执行。
#
# 如果您在这里删除一行,对应的提交将会丢失。
#
# 然而,如果您删除全部内容,变基操作将会终止。
#
# 注意空提交已被注释掉*//*
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
## //将3个commit合并到一起,注意是合并到一起,仍然时3个log,不能删除其中的log,删除之后相应的代码也删除了。~~ version 1.0version 2.0 for test 合并后的commitversion 3.0 for test*/git push -f origin users/cgf/feature_for_test//改完之后同样推送到远程github上/*
commit 27e3a734fdffc62091205f78373286e33609c34d (HEAD -> users/cgf/feature_for_test_1, origin/users/cgf/feature_for_test_1)
Author: CGF <872980563@qq.com>
Date: Sun Jun 16 22:10:24 2024 +0800version 3.0 for test 合并的前的commit
commit 44694b03db7a93c7cc4866d250d16fcbfa2d966a
Author: CGF <872980563@qq.com>
Date: Sun Jun 16 22:09:00 2024 +0800version 2.0 for testcommit 4b49d4f3b6f2ec8ae640d545861b141b0eb171c4
Author: CGF <872980563@qq.com>
Date: Sun Jun 16 21:29:54 2024 +0800version 1.0commit 3c21492dd15c489fe0c3e2a6a300660198260f57 (origin/master, origin/HEAD, master)
Author: shaoudelaochao <872980563@qq.com>
Date: Wed Oct 19 23:34:38 2022 +0800imu alignment
*//*
[分离头指针 b58b9d2] version 1.0Date: Sun Jun 16 21:29:54 2024 +08001 file changed, 4 insertions(+), 1 deletion(-)
Successfully rebased and updated refs/heads/users/cgf/feature_for_test_1.
caiganfei@caiganfei-WEI6-14-IML:~/github_test/learngit/ImuAlignment/ImuAlignment$ git log
commit b58b9d24b40501c10ac1d7746628100af82cfdcc (HEAD -> users/cgf/feature_for_test_1)
Author: CGF <872980563@qq.com>
Date: Sun Jun 16 21:29:54 2024 +0800version 1.0version 2.0 for test 合并后的commitversion 3.0 for testcommit 3c21492dd15c489fe0c3e2a6a300660198260f57 (origin/master, origin/HEAD, master)
Author: shaoudelaochao <872980563@qq.com>
Date: Wed Oct 19 23:34:38 2022 +0800imu alignment
*/
6、保存当前改动的代码:
git stash save "test 20240616" //将改动的代码暂时保存
/*
保存工作目录和索引状态 On users/cgf/feature_for_test_1: test 20240616
*/git stash list //查看保存的版本/*
stash@{0}: On users/cgf/feature_for_test_1: test 20240616
*/git stash apply stash@{0} //恢复版本```7、手动获取版本
git branch -a; //查看所有分支
git fetch orin develop;//获取develop分支版本
git checkout develop;//切换到develop分支