强行覆盖远程的gitlab 出错

需要删除原来的.git 文件  重新生成一次

强行覆盖远程的gitlab  出错  

我这里出错的原因是 因为我本地一个readme.md和远程的README.MD文本内容不同

我将本地的readme.md 删除后重新操作就对了

1.删除原来的.git文件

Administrator@USER-20170819XG MINGW64 /e/unicomWorkSpace/demoproject_GitLab
$ git init
Initialized empty Git repository in E:/unicomWorkSpace/demoproject_GitLab/.git/

Administrator@USER-20170819XG MINGW64 /e/unicomWorkSpace/demoproject_GitLab (master)
$ git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        .gitignore
        1.txt
        2.txt
        pom.xml
        readme.md
        readme.txt
        src/

nothing added to commit but untracked files present (use "git add" to track)

Administrator@USER-20170819XG MINGW64 /e/unicomWorkSpace/demoproject_GitLab (master)
$ git add .
warning: LF will be replaced by CRLF in .gitignore.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in pom.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in src/main/java/com/unicom/DemoprojectApplication.java.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in src/main/resources/application.yml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in src/test/java/com/unicom/DemoprojectApplicationTests.java.
The file will have its original line endings in your working directory.

Administrator@USER-20170819XG MINGW64 /e/unicomWorkSpace/demoproject_GitLab (master)
$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

        new file:   .gitignore
        new file:   1.txt
        new file:   2.txt
        new file:   pom.xml
        new file:   readme.md
        new file:   readme.txt
        new file:   src/main/java/com/unicom/DemoprojectApplication.java
        new file:   src/main/java/com/unicom/common/ResultVOUtil.java
        new file:   src/main/java/com/unicom/common/ResultVo.java
        new file:   src/main/java/com/unicom/common/resut.java
        new file:   src/main/java/com/unicom/controller/UserController.java
        new file:   src/main/java/com/unicom/dao/UserMapper.java
        new file:   src/main/java/com/unicom/dataobject/User.java
        new file:   src/main/java/com/unicom/repository/UserRepository.java
        new file:   src/main/java/com/unicom/service/UserService.java
        new file:   src/main/java/com/unicom/service/impl/UserServiceImpl.java
        new file:   src/main/java/com/unicom/w.java
        new file:   src/main/resources/application.yml
        new file:   src/main/resources/mapper/UserMapper.xml
        new file:   src/test/java/com/unicom/DemoprojectApplicationTests.java
        new file:   src/test/java/com/unicom/repository/UserRepositoryTest.java


Administrator@USER-20170819XG MINGW64 /e/unicomWorkSpace/demoproject_GitLab (master)
$ git commit -am 'first'
[master (root-commit) 3925749] first
 21 files changed, 623 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 1.txt
 create mode 100644 2.txt
 create mode 100644 pom.xml
 create mode 100644 readme.md
 create mode 100644 readme.txt
 create mode 100644 src/main/java/com/unicom/DemoprojectApplication.java
 create mode 100644 src/main/java/com/unicom/common/ResultVOUtil.java
 create mode 100644 src/main/java/com/unicom/common/ResultVo.java
 create mode 100644 src/main/java/com/unicom/common/resut.java
 create mode 100644 src/main/java/com/unicom/controller/UserController.java
 create mode 100644 src/main/java/com/unicom/dao/UserMapper.java
 create mode 100644 src/main/java/com/unicom/dataobject/User.java
 create mode 100644 src/main/java/com/unicom/repository/UserRepository.java
 create mode 100644 src/main/java/com/unicom/service/UserService.java
 create mode 100644 src/main/java/com/unicom/service/impl/UserServiceImpl.java
 create mode 100644 src/main/java/com/unicom/w.java
 create mode 100644 src/main/resources/application.yml
 create mode 100644 src/main/resources/mapper/UserMapper.xml
 create mode 100644 src/test/java/com/unicom/DemoprojectApplicationTests.java
 create mode 100644 src/test/java/com/unicom/repository/UserRepositoryTest.java

Administrator@USER-20170819XG MINGW64 /e/unicomWorkSpace/demoproject_GitLab (master)
$ git remote add origin https://gitlab.com/yangjiabin/demo.git

Administrator@USER-20170819XG MINGW64 /e/unicomWorkSpace/demoproject_GitLab (master)
$ git branch
* master

Administrator@USER-20170819XG MINGW64 /e/unicomWorkSpace/demoproject_GitLab (master)
$ git branch -r    这里查询不到   在http情况下要  git push之后  (需要输入用户名密码才行)     

Administrator@USER-20170819XG MINGW64 /e/unicomWorkSpace/demoproject_GitLab (master)
$ git push -u origin master
To https://gitlab.com/yangjiabin/demo.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://gitlab.com/yangjiabin/demo.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.

Administrator@USER-20170819XG MINGW64 /e/unicomWorkSpace/demoproject_GitLab (master)
$ git push -u -f origin master               这里需要输入用户名和密码
Counting objects: 39, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (26/26), done.
Writing objects: 100% (39/39), 9.21 KiB | 314.00 KiB/s, done.
Total 39 (delta 1), reused 0 (delta 0)
remote: GitLab: You are not allowed to force push code to a protected branch on this project.
To https://gitlab.com/yangjiabin/demo.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://gitlab.com/yangjiabin/demo.git'

Administrator@USER-20170819XG MINGW64 /e/unicomWorkSpace/demoproject_GitLab (master)
$

Administrator@USER-20170819XG MINGW64 /e/unicomWorkSpace/demoproject_GitLab (master)
$ git pull
warning: no common commits
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From https://gitlab.com/yangjiabin/demo
 * [new branch]      master     -> origin/master
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=origin/<branch> master


Administrator@USER-20170819XG MINGW64 /e/unicomWorkSpace/demoproject_GitLab (master)
$ git push -u -f origin master
Counting objects: 39, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (26/26), done.
Writing objects: 100% (39/39), 9.21 KiB | 294.00 KiB/s, done.
Total 39 (delta 1), reused 0 (delta 0)
remote: GitLab: You are not allowed to force push code to a protected branch on this project.
To https://gitlab.com/yangjiabin/demo.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://gitlab.com/yangjiabin/demo.git'

Administrator@USER-20170819XG MINGW64 /e/unicomWorkSpace/demoproject_GitLab (master)
$ git pull --rebase origin master
From https://gitlab.com/yangjiabin/demo
 * branch            master     -> FETCH_HEAD
First, rewinding head to replay your work on top of it...
Applying: first
.git/rebase-apply/patch:641: new blank line at EOF.
+
.git/rebase-apply/patch:681: new blank line at EOF.
+
warning: 2 lines add whitespace errors.
Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...

Administrator@USER-20170819XG MINGW64 /e/unicomWorkSpace/demoproject_GitLab (master)
$ git pull --rebase origin master
error: cannot pull with rebase: You have unstaged changes.
error: please commit or stash them.

Administrator@USER-20170819XG MINGW64 /e/unicomWorkSpace/demoproject_GitLab (master)
$ git status
On branch master
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        deleted:    README.md
        deleted:    readme.md

no changes added to commit (use "git add" and/or "git commit -a")

Administrator@USER-20170819XG MINGW64 /e/unicomWorkSpace/demoproject_GitLab (master)
$ git add .

Administrator@USER-20170819XG MINGW64 /e/unicomWorkSpace/demoproject_GitLab (master)
$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        deleted:    README.md
        deleted:    readme.md


Administrator@USER-20170819XG MINGW64 /e/unicomWorkSpace/demoproject_GitLab (master)
$ git commit -am '1'
[master 2f9c9e3] 1
 2 files changed, 1 deletion(-)
 delete mode 100644 README.md
 delete mode 100644 readme.md

Administrator@USER-20170819XG MINGW64 /e/unicomWorkSpace/demoproject_GitLab (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=origin/<branch> master


Administrator@USER-20170819XG MINGW64 /e/unicomWorkSpace/demoproject_GitLab (master)
$ git pull --rebase origin master
From https://gitlab.com/yangjiabin/demo
 * branch            master     -> FETCH_HEAD
Current branch master is up to date.

Administrator@USER-20170819XG MINGW64 /e/unicomWorkSpace/demoproject_GitLab (master)
$ git push -u -f origin master
Counting objects: 41, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (28/28), done.
Writing objects: 100% (41/41), 9.44 KiB | 322.00 KiB/s, done.
Total 41 (delta 2), reused 0 (delta 0)
To https://gitlab.com/yangjiabin/demo.git
   aba7fa8..2f9c9e3  master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.

Administrator@USER-20170819XG MINGW64 /e/unicomWorkSpace/demoproject_GitLab (master)
$
 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

! [remote rejected] master -> master (pre-receive hook declined)

2018年08月28日 19:17:57 北京流年 阅读数 3210

 版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010648159/article/details/82153119

! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to ‘https://code.xxxx.com.cn/xxxx/xxxx-Android.git
出现这个问题的原因是远程库和本地库不一致造成的,那么我们把远程库同步到本地库就可以了

解决办法

git pull --rebase origin master

这行指令的意思是把远程库中的更新合并到本地库中,-rebase的作用是取消本地库中刚刚的commit,
并把他们接到更新后的版本库之中。

转型人工智能!如何打造属于自己的“offer收割机”?

实战讲师总结AI人工智能学习路线规划,进军人工智能领域程序员免费领!

  • qq_42462576

    qq_42462576: 执行该命令之后还是报同样的错误(2周前#1楼)查看回复(1)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值