git常用的六个命令是什么?

为什么要使用git?

  • 代码管理,写完代码之后需要把它备份到一个仓库

  • 版本控制

  • 团队协作

Git 常用的六个命令

1、“git clone”克隆代码;

2、“git log”查看日志;

3、“git tag”查看标签;

4、“git branch”查看分支;

5、“git branch -a”查看远程分支;

6、“git pull”拉取。

常见错误

1、

error: failed to push some refs to 'git@github.com:....." Updates were rejected because the remote contains work that you do not have locally.

This is usually caused by another repository pushing to

解决

具体解决就是先pull合并,然后再push

$ git pull --rebase origin master
From https://github.com/suyunzzz/aiimooc_lesson
 * branch            master     -> FETCH_HEAD
Successfully rebased and updated refs/heads/master.
$ git push -u origin master
Enumerating objects: 27, done.
Counting objects: 100% (27/27), done.
Delta compression using up to 12 threads
Compressing objects: 100% (22/22), done.
Writing objects: 100% (25/25), 41.31 MiB | 2.08 MiB/s, done.
Total 25 (delta 5), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (5/5), completed with 2 local objects.
remote: warning: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
remote: warning: See http://git.io/iEPt8g for more information.
remote: warning: File odometry_pic_and_video/ndt_map.pcd is 92.26 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB
To https://github.com/suyunzzz/aiimooc_lesson.git
   d6accd1..416617c  master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.

2、fatal: refusing to merge unrelated histories

这是因为远程仓库已经存在代码记录了,并且那部分代码没有和本地仓库进行关联,我们可以使用如下操作允许pull未关联的远程仓库旧代码:

git pull origin master --allow-unrelated-histories

然后我们可以push代码了

$ git pull origin  master
From https://github.com/suyunzzz/Airborn_PointCLoudGPF
 * branch            master     -> FETCH_HEAD
fatal: refusing to merge unrelated histories

11604@s MINGW64 ~/Desktop/science_code/GPF_修改 (master)
$ git pull origin master --allow-unrelated-histories
From https://github.com/suyunzzz/Airborn_PointCLoudGPF
 * branch            master     -> FETCH_HEAD
error: The following untracked working tree files would be overwritten by merge:
        README.md
Please move or remove them before you merge.
Aborting

11604@s MINGW64 ~/Desktop/science_code/GPF_修改 (master)
$

11604@s MINGW64 ~/Desktop/science_code/GPF_修改 (master)
$ git pull origin master --allow-unrelated-histories
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 2 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (2/2), 585 bytes | 30.00 KiB/s, done.
From https://github.com/suyunzzz/Airborn_PointCLoudGPF
 * branch            master     -> FETCH_HEAD
   59035e0..50da614  master     -> origin/master
Already up to date!
Merge made by the 'recursive' strategy.

11604@s MINGW64 ~/Desktop/science_code/GPF_修改 (master)
$ git pull

11604@s MINGW64 ~/Desktop/science_code/GPF_修改 (master)
$ ^C

11604@s MINGW64 ~/Desktop/science_code/GPF_修改 (master)
$ git push
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


11604@s MINGW64 ~/Desktop/science_code/GPF_修改 (master)
$  git push --set-upstream origin master

Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Delta compression using up to 12 threads
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 1.21 MiB | 407.00 KiB/s, done.
Total 5 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), done.
To https://github.com/suyunzzz/Airborn_PointCLoudGPF.git
   50da614..8778f7b  master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.

更多web开发知识,请查阅 HTML中文网 !!

以上就是git常用的六个命令是什么?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » 其他答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏