Git怎么用

原创
2020/09/28 10:16
阅读数 65

首先去GitHubtHub上新建一个仓库,然后在电脑上下载git客户端,打开git bash,cd /F,cd到自己代码所在的文件夹,然后git clone https://github.com/phyzhenli/Simon_Speck_Ciphers_erro.git,这时所在的目录就会有一个下载下来的仓库文件夹,把代码拷贝进仓库里面,然后git add .或者git add 文件名,然后git commit -m "feast: first time",然后git push origin master就可以了:

git clone http://192.168.64.114/zli/fde.git
cd fde
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master

如果显示没有origin就按照提示git push --set-upstream origin master一下。

每一步以后都可以git status,如果git add .以后更改了文件夹又git add .那么缓存区的文件夹会再添加一次,需要git checkout .一下,清空缓存区,重新git add .

也可以先建一个一模一样的文件夹,进去以后git init,然后git clone,再把git clone得到的文件夹删掉(或者git remote add origin https://github.com/phyzhenli/Simon_Speck_Ciphers_erro.git )这样相当于自己init的文件夹就是git clone的文件夹,然后一样把文件拷进来,git add、git commit、git push origin master就可以了:

cd existing_folder
git init
git remote add origin http://192.168.64.114/zli/fde.git
git add .
git commit -m "Initial commit"
git push -u origin master

在git remote add origin的时候有可能已经连接到了旧的远程仓库,这时候需要先查看连接,然后取消掉即可:

git remote -v
git remote rm origin

git push以后如何无缝回滚?

参考: https://blog.csdn.net/guozhaohui628/article/details/78922946 https://blog.csdn.net/u013201439/article/details/80140863

采用git reset --soft的办法,本地代码不会变旧:
1.首先过git reflog看HEAD指在最新,然后git reset --soft HEAD~1把HEAD减1,或者用git reset --soft [commit id]指向历史版本,[commit id]在history里面可以找到。
2.HEAD的指向都是commit,所以没有办法撤消,可以用git commit --amend修改commit,但修改的是上一次的commit。
然后直接git push -f -u origin master,搞定。

采用git reset --hard的办法,本地代码会变旧:
1.首先过git reflog看HEAD指在最新,然后git reset --hard HEAD~1把HEAD减1,或者用git reset -- hard [commit id]指向历史版本,[commit id]在history里面可以找到。
2.此时处于上一次的commit,直接git push -f -u origin master,搞定。
然后再次修改代码,重新add。

在网页上修改了代码导致push产生冲突: 在本地git pull一下,会提示conflict,手动解决冲突后直接push。

遇到error: RPC failed; HTTP 500 curl 22 The requested URL returned error: 500 Internal Server Error的问题,应该是http协议下文件太大了,

参考: https://stackoverflow.com/questions/44780221/git-push-failing-http-500-curl-22-the-requested-url-returned-error-500-internal https://www.jianshu.com/p/8caa35e82196 https://blog.csdn.net/lcyaiym/article/details/77282354

采用ssh推送。

gitlab bug:

对于一个新建的网站上的仓库来说,本地采用ssh推送上去,网站不会有更新,只有采用http推送的以后网站才会看到更新,但http无法推送大的,所以至少需要一次小的http推送,之后ssh还是http就无所谓了。

#2020.09.20:

ssh直接崩了,拉也拉不下来。

git commit后想要修改commit:

git commit --amend进入编辑,然后修改最上面的commit,保存退出即可。

展开阅读全文
加载中

作者的其它热门文章

0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部