写在前面
第一次写博客。从没想到自己会想来干这样一个曾经以为多此一举到后来觉得我不配的事情,但对越来越杂乱的生活来说,每天对自己进行一定的总结变得必不可少。常常会在某个瞬间反思起自己在过去的一个小时、一天、一周做了什么?我得到或失去了什么?转眼间就要迎来年底——十二月,在这特殊的一年,我有什么收获?虚度了多少时间?不能再等了,现在就要开始思考自己为每一件事情耗费的时间是否值得,是否可以花费更少;现在是2020年的十一月底,这也许就是我的进步吧。
没有怎么用过博客,不知在这个大佬云集的平台是否接受一个计算机课程匮乏的地信大二学生的碎碎念与其万分菜鸡的发言T^T。
希望再忙也要坚持至少一周写一小篇吧!
原因
希望进行打卡学习
第一步:下载安装
八点到官网下载git2.29.2.2,失败告终
尝试到十点二十,终于下载成功!
所以以后到国外网站下载什么东西,一定要在上午十点半以后去啊!!
第二步:廖雪峰教程
基本过程
pwd/cd
–> touch/vi xxx
–> git add
–> git commit -m “remarks”
–> git log
–> git log --pretty=oneline
–> git reset --hard HEAD^
–> git reset --hard commit_id 用到了指针的知识
–> git reflog
–> git checkout
–> git status
–> git diff HEAD – 查看版本的差异
–> git restore – 撤销文件在工作区的修改
–> git reset HEAD 撤销在暂存区的修改,重新放回工作区
–> rm xx
–> git rm xx
–> 创建SHH KEY,或者直接用http
疑问
虽然看了也看不全明白,好歹比没看好
1.https与ssh协议的区别?
见博客:https://blog.youkuaiyun.com/qq_42108192/article/details/90168968?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromBaidu-1.control&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromBaidu-1.control
2.id_rsa私钥为什么不能告诉别人?
看到了公钥与私钥的用处,觉得问的很傻
第三步:错误出现
本来一开始想的是把从头到尾所有遇到的问题都整理一下,但是发现几个问题:
1.git中途多次被重新打开,报错记录已经缺少了许多。而检索搜索记录过于繁琐、信息量过大,对于自己今天操作遇到的问题针对性不强。
2.另外还考虑到git这个工具其中涉及到的学问很深,与其求大而全,不如把手里已有的资料好好看,不贪多嚼不烂。
3.时间不允许再看这方面更多,加上一点懒惰的心理,还有面对纷繁复杂的信息有些乱了阵脚,所以将就简单记录一下最后遇到的几个问题吧。
c
1.在即将执行向远程库提交文件时,不小心将新建仓库的命令全部复制下来并直接运行,发生了错误.细节已经查不到了。。。
2.这是需要push的具体信息
Rachel Du@DESKTOP-AF0JFS0 MINGW64 /d/Programming/gitstydy/acdgtovdo (master)
$ git push
fatal: No configured push destination.
Either specify the URL from the command-line or configure a remote repositorying
git remote add <name> <url>
and then push using the remote name
git push <name>
3.需要验证信息
Rachel Du@DESKTOP-AF0JFS0 MINGW64 /d/Programming/codes/C/c (master)
$ git push origin master
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
参考xh1997的回答:
如果在git push时出现了上述情况,或者说Please make sure you have the correct access rights and the repository exists.那么可以尝试两种解决办法
添加ssh公钥,首先查看自己本地的ssh公钥(cat ~/.ssh/id_rsa.pub)将输出的内容复制粘贴到你的github账号的Settings–>SSH and GPG keys然后点击New SSH keys添加你的公钥,title随便起一个就行。
如果在github上已经存在你的本地公钥了,那么你可以先删除远程仓库,然后再利用ssh公钥添加:
git remote remove 你的github名
git remote add origin git@github.com:你的账户名/仓库名.git
然后git push origin master试试
4.同上
Rachel Du@DESKTOP-AF0JFS0 MINGW64 /d/Programming/codes/C/c (master)
$ git pull --rebase origin master
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
5.这个错误就是 表示本地分支与远程分支之间没有连接起来
Rachel Du@DESKTOP-AF0JFS0 MINGW64 /d/Programming/codes/C/c (master)
$ git push origin
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin master
COCOLI_BK的回答:
只需要在输入 git push -u origin dev(远程分支名), 因为本身我就在本地的dev分支上面,所以可以直接 push,不在dev 分支的话需要 git checkout dev切换到dev分支,个人建议最好是本地分支新建的时候与远程分支命名一致。
这样就可以成功push
6.大概原因就是 意思是本地和远程的文件应该合并后才能上传本地的新文件
Rachel Du@DESKTOP-AF0JFS0 MINGW64 /d/Programming/codes/C/c (master)
$ git push --set-upstream origin master
To https://github.com/Rachel0305/learngit.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/Rachel0305/learngit.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
解决方法:
1、先拉下来,会自动合并的(不用操心)
git pull origin master
2、再上传
git push -u origin master
7.应该是需要一个具体的分支名,这里应该再加一个master就可以了
Rachel Du@DESKTOP-AF0JFS0 MINGW64 /d/Programming/codes/C/c (master)
$ git pull origin
remote: Enumerating objects: 16, done.
remote: Counting objects: 100% (16/16), done.
remote: Compressing objects: 100% (12/12), done.
Unpacking objects: 100% (16/16), 2.65 KiB | 96.00 KiB/s, done.
remote: Total 16 (delta 2), reused 10 (delta 0), pack-reused 0
From https://github.com/Rachel0305/learngit
* [new branch] main -> origin/main
* [new branch] master -> origin/master
You asked to pull from the remote 'origin', but did not specify
a branch. Because this is not the default configured remote
for your current branch, you must specify a branch on the command line.
8.没时间啦,就先粘贴在这里了!
Rachel Du@DESKTOP-AF0JFS0 MINGW64 /d/Programming/codes/C/c (master)
$ git pull origin master
From https://github.com/Rachel0305/learngit
* branch master -> FETCH_HEAD
fatal: refusing to merge unrelated histories
在后面加了一句过后就变成这样了
Rachel Du@DESKTOP-AF0JFS0 MINGW64 /d/Programming/codes/C/c (master)
$ git pull --rebase origin master
From https://github.com/Rachel0305/learngit
* branch master -> FETCH_HEAD
Successfully rebased and updated refs/heads/master.
再git push origin master
就行了
acdgtovdo
1.新建本地分支后将本地分支推送到远程库, 使用git pull 或者 git push 的时候报错
Rachel Du@DESKTOP-AF0JFS0 MINGW64 /d/Programming/gitstydy/acdgtovdo (master)
$ git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=<remote>/<branch> master
是因为本地分支和远程分支没有建立联系 (使用git branch -vv 可以查看本地分支和远程分支的关联关系) .根据命令行提示只需要执行以下命令即可
git branch --set-upstream-to=origin/远程分支的名字 本地分支的名字
Rachel Du@DESKTOP-AF0JFS0 MINGW64 /d/Programming/gitstydy/acdgtovdo (master)
$ git branch --set-upstream-to=<remote>/<branch> master
bash: remote: No such file or directory
第四步:总结流程
参考COCOLI_BK的博客:
假如外出工作,需要在另一台电脑上面pull自己的某个git远程项目到本地:
git init
git pull https://github.com/TTyb/54qjLogin (远程仓库url)
下载的这个项目更改后需要push的会出现:
$ git push
fatal: No configured push destination.
Either specify the URL from the command-line or configure a remote repository using
git remote add <name> <url>
and then push using the remote name
git push <name>
then
这个时候第一次push需要网址:
$ git add --all 或者使用 git add .(所得的文件) | git add file.js(对用指定文件)
$ git commit -m "提交信息"
$ git remote add origin '远程仓库url'
$ git push -u origin origin(对应远程分支名)
然后下一次就不用那么麻烦了,直接:
$ git add --all | git add .(所得的文件) | git add file.js(对用指定文件)
$ git commit -m "信息"
$ git push
第五步:以后还要再查的
2.git push -u origin master中的 -u 是什么意思?
3.rebase命令是什么意思?
4.怎么批量将文件导入暂存区
5.GitHub的IP地址的最后一位数字为什么有时候是2,有时候是3?
6.ping是什么?
7.branches到底是什么情况?main和master?
本次搜索历史555希望以后不要再直接粘贴百度粘贴关闭了!