相关疑难解决方法(0)

如何将Git存储库还原为以前的提交

如何从当前状态恢复为在某个提交时创建的快照?

如果我这样做git log,那么我得到以下输出:

$ git log
commit a867b4af366350be2e7c21b8de9cc6504678a61b`
Author: Me <me@me.com>
Date:   Thu Nov 4 18:59:41 2010 -0400

blah blah blah...

commit 25eee4caef46ae64aa08e8ab3f988bc917ee1ce4
Author: Me <me@me.com>
Date:   Thu Nov 4 05:13:39 2010 -0400

more blah blah blah...

commit 0766c053c0ea2035e90f504928f8df3c9363b8bd
Author: Me <me@me.com>
Date:   Thu Nov 4 00:55:06 2010 -0400

And yet more blah blah...

commit 0d1d7fc32e5a947fbd92ee598033d85bfc445a50
Author: Me <me@me.com>
Date:   Wed Nov 3 23:56:08 2010 -0400

Yep, more blah blah.
Run Code Online (Sandbox Code Playgroud)

如何从11月3日恢复提交,即提交0d1d7fc

git git-revert git-checkout git-reset

7278
推荐指数
42
解决办法
549万
查看次数

使用Git将我的最后一次X提交压缩在一起

如何使用Git将我最后的X提交压缩成一个提交?

git squash git-squash

3294
推荐指数
38
解决办法
147万
查看次数

强制"git push"覆盖远程文件

我想推送我的本地文件,并将它们放在远程仓库上,而不必处理合并冲突.我只是希望我的本地版本优先于远程版本.

我怎么能用Git做到这一点?

git git-push

702
推荐指数
6
解决办法
66万
查看次数

Git - push.default"匹配"和"简单"之间有什么区别

我一直在使用git一段时间,但我自己从来没有设置过新的远程仓库,我一直很好奇这样做.我一直在阅读教程,我对如何让"git push"工作感到困惑.

如果我只是用git push它要求我查看默认分支(?)指向?它为我提供的这两个选项有什么区别?

git config --global push.default matching
git config --global push.default simple
Run Code Online (Sandbox Code Playgroud)

匹配只是推动我在本地仓库上的任何分支,如果它们不匹配,我必须手动告诉它推送我所拥有的任何新的本地分支,对吗?这是最好的做法还是最简单的?

git git-pull git-push git-remote

275
推荐指数
3
解决办法
10万
查看次数

更新被拒绝,因为您当前分支的提示背后提示:它的远程对应物.整合远程变更(例如

更新被拒绝,因为您当前分支的提示背后提示:它的远程对应物.集成远程更改.

我试图将本地octopress博客推向远程分支.但它上面说错误.

另一个是:我是否必须管理或推送本地更改到源或源分支.

当我做username.github.io时,我会看到我的本地博客的远程版本.(我使用rake deploy命令)但是我没有在我的username.github.io看到更新的博客.我怀疑分支上的原点和资源.

github github-pages github-flavored-markdown

113
推荐指数
1
解决办法
29万
查看次数

Git说本地分支是远程分支的后面,但事实并非如此

场景:

  1. 我做了一个新的分支
  2. 破解它
  3. 提交它
  4. 推它
  5. 再破解它
  6. 再次提交
  7. 试着再次推动

Git回应:

更新被拒绝,因为您当前分支的提示落后于其远程对手.等等

我是唯一一个黑客入侵这个分支的人 - 没有其他人在触摸它.远程分支实际上位于本地分支之后.我根本不应该拉.

(如果我拉,Git报告两者之间的冲突,并迫使我将分支合并到自身)

为什么会这样(可能)发生?我该如何诊断/修复它?

要清楚,我不会在任何地方分支,也没有其他人在研究它:

Remote: Commit A -------- Commit B  

Local:  Commit A -------- Commit B -------- Commit C  
Run Code Online (Sandbox Code Playgroud)

C是B的直接延续,不涉及分支.但是git认为C是A的一个分支:

Remote: Commit A -------- Commit B  

                  ------- Commit C  
                /  
Local:  Commit A -------- Commit B  
Run Code Online (Sandbox Code Playgroud)

不是; 它是B的直接延续.

git git-push

81
推荐指数
2
解决办法
16万
查看次数

Git在修改提交后阻止推送

通常,我只是跑

git add file
git commit
git push
Run Code Online (Sandbox Code Playgroud)

但如果我推送之前修改了提交(with git commit --amend),则下一次推送失败

hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Run Code Online (Sandbox Code Playgroud)

如何让git在不合并分支的情况下推送更改?我只有一个分支(master),我是唯一一个使用这个回购的人,为什么这么说呢?

git branch -a:

* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
Run Code Online (Sandbox Code Playgroud)

编辑:使用gitk HEAD @{u},我看到我有2个分支,一个用原始提交,另一个用修改提交.

git git-push git-amend git-commit

41
推荐指数
3
解决办法
5万
查看次数

是否可以将多个本地文件夹连接到 Github 中的一个存储库?

我有两个不同路径的不同文件夹,我想将它们链接到同一个存储库。出于说明目的,两个不同的文件夹是

Folder 1: C:\Users\Tea\Folder1
Folder 2: C:\Users\Tea\Folder2
Run Code Online (Sandbox Code Playgroud)

文件夹 1 最初链接到我的存储库,但我也想将文件夹 2 链接到存储库,以便我也可以从那里推送文件。

这是我尝试过的

cd C:\Users\Tea\Folder2
git init
git add .
git commit -m "initial commit from Folder 2"
git remote set-url origin --push --add http://github.com/<my username and repository> 
Run Code Online (Sandbox Code Playgroud)

最后一行是根据这篇文章完成的:从多个远程位置拉/推

但是,我在执行时收到错误消息

git push origin master
Run Code Online (Sandbox Code Playgroud)

要我做一个 git fetch。更具体地说,它写道:

! [ rejected ] master -> master(fetch first)
error: failed to push some refs to 'https://github.com/...'
hint: Updates were rejected because the remote contains work that you do
hint: not have …
Run Code Online (Sandbox Code Playgroud)

git github

6
推荐指数
2
解决办法
8603
查看次数

如何修复Git中的问题:"更新被拒绝,因为推送的分支提示位于其远程对应的后面"

我正在尝试将提交推送到远程并收到此错误消息:

$  git push origin master
To git@git1.eu1.frbit.com:hbrosuru.git
! [rejected]        ab68c0485d -> master (non-fast-forward)
error: failed to push some refs to 'git@git1.eu1.frbit.com:hbrosuru.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and 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.
Run Code Online (Sandbox Code Playgroud)

我想通过将多个本地分支推送到这个单独的远程分支,我已经陷入困境,我想基本上清除服务器上的内容并推动整个分支的新鲜.这是可能的,还是有更好的方法来解决这个错误?

PS.这个远程分支托管在Fortrabbit上,所以我没有完全访问服务器来简单地删除分支并创建一个新分支,因为Fortrabbit的部署机制基于Git.

git version-control fortrabbit

5
推荐指数
1
解决办法
7399
查看次数

通过公共WIFI的GitLab(SSH),端口22被阻止

我使用星巴克wifi,尝试推送到gitlab.com仓库时得到以下信息:

  $ git push origin master
  ssh: connect to host gitlab.com port 22: Connection refused
  fatal: Could not read from remote repository.
Run Code Online (Sandbox Code Playgroud)

我尝试通过GitHub改编GitHub的解决方法:Github(SSH),通过将以下内容添加到〜/ .ssh / config来阻止端口22

 Host gitlab.com
        Hostname gitlab.com
        Port 443
Run Code Online (Sandbox Code Playgroud)

但这不起作用,因为我收到此错误:

 $ git push origin master
 ssh_exchange_identification: Connection closed by remote host
 fatal: Could not read from remote repository.

 Please make sure you have the correct access rights
 and the repository exists.
Run Code Online (Sandbox Code Playgroud)

我有一个解决方法,可以使用端口443推送到GitLab.com吗?

ssh wifi gitlab

5
推荐指数
2
解决办法
6620
查看次数

无论我做什么,我都无法推送我的代码并不断收到相同的错误

我正在尝试将我的代码推送到我的远程分支,但一直收到此错误:

! [rejected] (non-fast-forward)
error: failed to push some refs to 'git@github.com:
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details
Run Code Online (Sandbox Code Playgroud)

我认为可能导致这种情况的原因是我在 github 上的 README.md 中修复了一个错字,而不是通过我的本地环境。

我已经查看了堆栈溢出并尝试了他们针对此问题提到的命令,例如git pull, git pull --rebase, git pull origin master,git push --f和许多其他与无济于事。

我还尝试了以下问题的答案,但没有成功:

更新被拒绝,因为您当前分支的提示在提示后面:它的远程副本。集成远程更改(例如 [重复]

无法推送到 GitHub …

git github git-push

5
推荐指数
1
解决办法
1160
查看次数

用develop覆盖master

在我们的项目中,主分支完全崩溃了。它认为它领先一些承诺,如果我们尝试合并开发,则表明存在大量冲突。它已经被打破很长时间了,所以开发中发生了很多事情(解决了太多冲突)。

我只想用dev覆盖master中的所有内容(因此master基本上等于dev)。我该怎么做呢?

我尝试删除本地master中的所有内容,然后运行以下命令:

git checkout master
git reset --hard develop
Run Code Online (Sandbox Code Playgroud)

似乎给我所有正确的文件,但是当我尝试推送主文件时,出现此错误:

Updates were rejected because the tip of your current branch is behind
Run Code Online (Sandbox Code Playgroud)

git merge git-merge merge-conflict-resolution

2
推荐指数
2
解决办法
1678
查看次数