简体   繁体   English

git push 不将本地更改提交到远程存储库

[英]git push not submitting local changes to remote repository

I have followed following steps.我遵循了以下步骤。

$git log --oneline

commit5
commit4
commit3
commit2
commit1

$git checkout commit3

$git log --oneline
commit3
commit2
commit1

Now i made changes to few file.

$git add .
$git commit -m "commit6"
$git log --oneline
commit6
commit3
commit2
commit1

Now, i try to push these changes to remote repository.

$git push -f origin master


This command is not pushing my commit6 to the remote server.
I am getting the message everything up-to-date.

How to push commit6 to remote repository.如何将 commit6 推送到远程存储库。 I want remote repository state similar to my local state.我想要类似于我的本地状态的远程存储库状态。

Thanks in advance.提前致谢。

$ git checkout commit3

I will assume here that you used a raw hash ID to check out, as in, eg:我将在这里假设您使用原始哈希 ID 来签出,例如:

$ git checkout fe3fec53a6
Note: switching to 'fe3fec53a6'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at fe3fec53a6 Merge branch 'bc/rev-list-without-commit-line'

Please read all of the text that git checkout printed.请阅读git checkout打印的所有文本。

Now i made changes to few file.现在我对几个文件进行了更改。

 $ git add . $ git commit -m "commit6" $ git log --oneline commit6 commit3 commit2 commit1

You have now created, in effect, a new unnamed branch.您现在实际上已经创建了一个新的未命名分支。 This new branch ends at your new commit6 .这个新分支在你的新commit6处结束。

Your existing master branch remains unchanged.您现有的master分支保持不变。 It continues to end at the existing commit5 that you saw in the original output.它继续以您在原始输出中看到的现有commit5结束。

How to push commit6 to remote repository.如何将 commit6 推送到远程存储库。 I want remote repository state similar to my local state.我想要类似于我的本地状态的远程存储库状态。

Depending on the remote repository in question, this may be anywhere from very difficult to impossible.根据所讨论的远程存储库,这可能非常困难到不可能。 In particular, your local state uses a detached HEAD .特别是,您的本地状态使用分离的 HEAD You may not be able to put the other repository into detached-HEAD state.您可能无法将其他存储库置于 detached-HEAD 状态。

You can send the new commit to the remote repository, but you will likely wish to use a branch name to do this.可以将新提交发送到远程存储库,但您可能希望使用分支名称来执行此操作。 When you are in detached HEAD mode, you are not on any branch .当您处于分离的 HEAD 模式时,您不在任何分支上 You made your commit6 on no branch at all .您根本没有任何分支上进行 commit6。

You could choose to discard commits 4 and 5 and instead use only commit 6, locally, as the tip commit of your (local) master branch.您可以选择放弃提交 4 和 5,而仅在本地使用提交 6 作为(本地) master分支的提示提交。 You can attempt to set the remote repository's master , over at origin , to this same state as well.你可以尝试设置远程仓库的master ,过在origin ,这个相同的状态为好。 The remote repository will be within its rights to refuse to discard commits 4 and 5, especially if you do not own the remote repository.远程存储库有权拒绝放弃提交 4 和 5,尤其是在您不拥有远程存储库的情况下。 If you do own the remote repository, you can set things up so that you can discard the commits there—but you have not told us whether this is the case.如果您确实拥有远程存储库,您可以进行设置,以便您可以丢弃那里的提交——但您没有告诉我们是否是这种情况。

You could choose to add a new commit to master locally, so that commit7 (the new one) comes immediately after commit5 , and send this new commit and its files to the remote repository.您可以选择在本地向master添加一个新提交,以便commit7 (新提交)在commit5之后立即出现,并将此新提交及其文件发送到远程存储库。 This is more likely to succeed than the request to have the remote repository discard commits 4 and 5, since Git is built to add new commits without discarding existing ones.这比让远程存储库丢弃提交 4 和 5 的请求更有可能成功,因为 Git 旨在添加新提交而不丢弃现有提交。

You need to decide which of these actions is the most appropriate (or whether there's some alternative that's better than any of these).您需要决定这些操作中的哪一个是最合适的(或者是否有比其中任何一个都更好的替代方法)。 Should you wish to force the remote repository to discard commits, you will, in general, need some kind of "forced push".如果您希望强制远程存储库放弃提交,通常需要某种“强制推送”。 There are literally hundreds of existing StackOverflow questions about this.有数百个关于此的现有 StackOverflow 问题。

If you made changes to a few fies, the first thing you want to do is not如果您对几个 fies 进行了更改,那么您首先要做的就是不要

$git commit -m "commit6" $git commit -m "commit6"

But to add files to stage with git add file_name Then you can create a commit and push it to remote repo Make sure you have linked your offline repo with your remote first with git remote但是要使用git add file_name将文件添加到 stage 然后您可以创建一个提交并将其推送到远程仓库确保您已首先使用git remote将您的离线仓库与远程仓库相关联

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM