在此记录Github中git的基础指令,如:怎么将fork项目和源仓库同步;怎么删除分支;抛弃本地修改;上传本地修改;克隆github项目分支 等。
最近一直在用github,提交文件之类的操作常常需要用到git。所以在此记录。
就是项目所在的github网址,如下图,则克隆命令为:
fork项目的话,我没用git指令,而是直接在github中你想要fork到自己仓库的项目主页,点击fork按钮即可,如下:
如:
这个比较难。
先描述一下场景 :github上有一个项目 ( https://github.com/SpoonLabs/nopol.git ),我将Nopol这个项目fork到了我的仓库中( https://github.com/DehengYang/nopol ),然后使用下载到了本地,原本Nopol总共有4个分支,现在Nopol作者给Nopol添加了一个分支,我想把这个分支添加到我fork过来的Nopol中,这时候需要怎么操作呢?
在本地中打开终端(命令行):
后面几步我记得不是很清楚了,大概应该就是这样的(有待实践中进一步确认)。
参考 [1],[2]。
场景:在本地不小心使用 误创建了一个新的分支。现在需要删除分支,应该如何呢?
如下:
参考 [5] 。
参考 [6] 。
场景:我在本地项目中修改了几个文件,但是我现在不想要了,想删除修改,并在本地和github仓库中的代码同步。
在终端输入:
参考 [3] 和 [4]。
[1] Github进行fork后如何与原仓库同步 https://blog.csdn.net/matrix_google/article/details/
[2] git分支查看及切换 https://blog.csdn.net/_/article/details/
[3] git 放弃本地修改 https://www.cnblogs.com/qufanblog/p/7606105.html
[4] git 拉取远程分支到本地 https://blog.csdn.net/carfge/article/details/
[5] git删除本地分支 https://blog.csdn.net/github_/article/details/
[6] git上传本地分支到github项目分支 https://blog.csdn.net/_/article/details/
此外,还有如下网址也给了一些指导,故在此记录:
git常用命令以及如何与fork别人的仓库保持同步 https://www.cnblogs.com/-walker/p/7278951.html
git fetch 更新远程代码到本地仓库 https://www.cnblogs.com/chenlogin/p/6592228.html
场景: 我去年上传了一个github项目,但是当时还是小白,直接从本地各个地方拖拽文件夹上传,,,所以本地的文件不完整。
这次想用命令下载远程仓库代码,发现太大了。
但是呢,我本地的又不完整,所以我先参考的 [7],执行的是:,有一点用:
$ git fetch origin master
remote: Enumerating objects: 64, done.
remote: Counting objects: 100% (64/64), done.
remote: Total 2508 (delta 64), reused 64 (delta 64), pack-reused 2444
Receiving objects: 100% (2508/2508), 139.08 MiB | 162.00 KiB/s, done.
Resolving deltas: 100% (614/614), completed with 11 local objects.
From https://github.com/DehengYang/sfa-rfa
* branch master -> FETCH_HEAD
37a4543… master -> origin/master
可以看到reuse 64,我感觉是本地已有的文件没有重复下载。
但是呢,有一个不完整的文件夹没有覆盖掉,我现在得强行覆盖。
方案:
1)输入: (也可以分开输入,这样心里有底。) [8]
2)理论上这样就可以了,可以用看一下当前的状况,如果还不行就输入:,感觉这个命令非常过硬,强制执行。
$ git pull origin master
From https://github.com/DehengYang/sfa-rfa
* branch master -> FETCH_HEAD
Already up-to-date.
此外,在这样的场景下,我一开始输入的时候显示很多 ,参考[9],主要是两个命令: 可以添加这些没有被追踪的文件,使用 就可以移除。
正如上文所说,Git在未进行commit操作之前,存在三种状态:Untracked files,Changes not staged for commit及Changes to be committed,每种状态之间可以随意进行互相转换。了解这三种状态各自所对应的不同情况,能够帮助你方便有效的使用Git来管理项目。
场景: 我的一个图片名字叫
但是显示不出这张图片。
解决:
参考[10],改成:
即可。
这个问题我还没研究透,不想多写了。大概列出文献。
Is there a way to edit a commit message on GitHub? https://superuser.com/questions//is-there-a-way-to-edit-a-commit-message-on-github
git 查看某个文件下的某个commit的修改记录 https://blog.csdn.net/m_review/article/details/
如何修改Git commit的信息 https://www.cnblogs.com/shenh062326/p/git.html
场景:在本地仓库中,我删除了一个文件夹,然后git status就会发现:有很多deleted files。但是这种删除怎么同步到github仓库(origin master)呢?
解决方案:
参考:
How to remove multiple deleted files in Git repository https://stackoverflow.com/questions//how-to-remove-multiple-deleted-files-in-git-repository
git add -A 和 git add . 的区别 https://www.cnblogs.com/skura23/p/5859243.html
参考:git fetch 更新远程代码到本地仓库 http://www.cnblogs.com/chenlogin/p/6592228.html
[7] git fetch 更新远程代码到本地仓库 https://www.cnblogs.com/chenlogin/p/6592228.html
[8] git强制覆盖本地代码和强制推送本地到远程仓库 https://blog.csdn.net/sheep8521/article/details/
关于pull、fetch还参考了:
git pull命令 https://www.yiibai.com/git/git_pull.html
详解git pull和git fetch的区别: https://blog.csdn.net/weixin_/article/details/
[9] Git中三种文件状态及其转换 https://phplaber.iteye.com/blog/
[10] URLs with spaces do not render a links in markdown cells https://github.com/nteract/nteract/issues/914
在运行:git push origin master 的时候,出错:
fatal: unable to access ‘https://github.com/DehengYang/FL-APR-research.git/’: Failed to connect to github.com port 443: Timed out
先后在命令行(我的是windows git bash)中输入:
当然,也可能是网络不好,多试几次就行。
GihubMarkdown中的复选框按钮的实现 https://blog.csdn.net/Erice_s/article/details/
How to add color to Github’s README.md file https://stackoverflow.com/questions//how-to-add-color-to-githubs-readme-md-file
如何向Github README.md中添加图片 https://blog.csdn.net/_/article/details/
- git 获取最近一次提交的commit id https://blog.csdn.net/lonewolf/article/details/
- 在 GitHub 上利用 SHA-1 值(commit ID)搜索某一次的提交内容 https://blog.csdn.net/weixin_/article/details/
- github,退回之前的commit https://www.cnblogs.com/xiaomengzhang/p/3240788.html
- 修改文件,查看修改内容,git status、git diff(四) https://blog.csdn.net/_/article/details/
值得一看。
- git查看commit提交记录详情 https://blog.csdn.net/weixin_/article/details/
- Git 历史提交日志导出到文件中 https://blog.csdn.net/ianly123/article/details/
- git查看某一次commit里面的内容,即本次commit相对于原来的版本进行了哪些修改 https://www.cnblogs.com/hustdc/p/6596080.html
版权声明:
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若内容造成侵权、违法违规、事实不符,请将相关资料发送至xkadmin@xkablog.com进行投诉反馈,一经查实,立即处理!
转载请注明出处,原文链接:https://www.xkablog.com/cjjbc/45559.html