git push 不将更改发送到远程 git 存储库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1298499/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git push not send changes to remote git repository
提问by Tim
I am making changes to some file in my local git repository and then want to send the changes to the remote git repository from which the local was cloned via ssh.
我正在对本地 git 存储库中的某个文件进行更改,然后想将更改发送到远程 git 存储库,本地是通过 ssh 从中克隆的。
After run "git commit -a" on my local side, to send the changes to the remote, I run
在本地运行“git commit -a”后,将更改发送到远程,我运行
$ git push
Everything up-to-date
However I checked the remote files and they are not changed! Any idea?
但是我检查了远程文件,它们没有改变!任何的想法?
Thanks and regards!
感谢致敬!
采纳答案by Bombe
You probably pushed into a non-bare repository, i.e. a repository that has a working copy attached to it. You shouldn't have ignored the warning git push
gives you if it notices that this is the case.
您可能已推送到非裸存储库,即附加了工作副本的存储库。git push
如果它注意到这种情况,您不应该忽略警告给您。
Anyway, log in to the remote machine, change to the repository and do
无论如何,登录到远程机器,更改到存储库并执行
git checkout <whatever branch you're on>
There you go. Next time only push into bare repositories. :)
你去吧。下次只推送到裸存储库。:)
回答by knittl
have you tried the following?
你试过以下吗?
$ git push origin master:master
回答by rupi
I found that the issue was that I had not added the files to the update as well as a message. I fixed this by using the following commands:
我发现问题是我没有将文件添加到更新以及消息中。我使用以下命令修复了这个问题:
git add .
and then
进而
git commit -m "updates done by..."
and then
进而
git push origin <repo_name>
Hope this helps someone ;)
希望这有助于某人;)
回答by Programster
I had the same issue and it was because I had checked out to a point in the history(in this case a tag), rather than the end (head) of any branch or master. I would make the change and commit which would succeed and I would see the changes in my local history. When I ran git push, git stated everything was fine, but the change had not actually been submitted to the server (which can be seen by checking the logs, or by re-cloning the repo and checking it's logs). The best symptom of this mistake is seeing the message "Head detatched from ____"
我遇到了同样的问题,这是因为我已经签出了历史记录中的某个点(在这种情况下是一个标签),而不是任何分支或主节点的结尾(头部)。我会做出改变并提交,这会成功,我会看到我本地历史的变化。当我运行 git push 时,git 表示一切正常,但更改实际上并未提交到服务器(可以通过检查日志或重新克隆 repo 并检查其日志来查看)。此错误的最佳症状是看到消息“Head detatched from ____”
The Solution
解决方案
What one actually needs to do (if you have done what I've done) is create a new line of development by creating a branchand switching to that branch beforemaking the changes.
实际需要做的(如果您已经完成了我所做的)是通过创建一个分支并在进行更改之前切换到该分支来创建一个新的开发线。
git branch [a new branch name]
git checkout [a new branch name]
Then after committing the changes, if you want the changes to be pushed to the server you need to push the branch itself to the server.
然后在提交更改后,如果要将更改推送到服务器,则需要将分支本身推送到服务器。
git push -u origin [local branch name]
Now if you clone the repository, you should see your changes in the logs. However, next time you clone the repository, to be able to go to that point you just changed, you will need to checkout that branch, as you will default to being on the main line which is "further" down the development line from where you branched off.
现在,如果您克隆存储库,您应该会在日志中看到您的更改。但是,下次您克隆存储库时,为了能够到达您刚刚更改的那个点,您将需要签出该分支,因为您将默认位于开发线“更远”的主线上你分支了。
git checkout [branch name]
回答by Nir Duan
git commit --amend
Will change the commit ID
and make the remote repository "think" new changes has been made.
将更改commit ID
并使远程存储库“认为”已经进行了新的更改。
回答by Fernando Irarrázaval G
None of these solutions worked for me, and the commits would appear on my live website only after running GIT_WORK_TREE=/path/to/website git checkout -f
. If this is your case you have to add a "hook" to your git configuration.
这些解决方案都不适合我,只有在运行GIT_WORK_TREE=/path/to/website git checkout -f
. 如果这是你的情况,你必须在你的 git 配置中添加一个“钩子”。
Go to your the hooks folder inside your git folder:
cd ~/path/.git
cd hooks
nano post-receive
Write this line in the post-receive file:
GIT_WORK_TREE=/path/to/your/website/or/project/ git checkout -f
Lastly, you have to modify the permissions of the post-receive file:
chmod a+x post-receive
转到 git 文件夹中的 hooks 文件夹:
cd ~/path/.git
cd hooks
nano post-receive
在 post-receive 文件中写下这一行:
GIT_WORK_TREE=/path/to/your/website/or/project/ git checkout -f
最后,您必须修改 post-receive 文件的权限:
chmod a+x post-receive
This will execute that command every time you push, updating your commits on your remote project.
这将在您每次推送时执行该命令,更新您对远程项目的提交。
回答by Luis
I suggest you look into using gitosisfor hosting those git bare repositories. It's really easy to use after the initial setup.
我建议您考虑使用gitosis来托管那些 git 裸存储库。初始设置后,它真的很容易使用。
回答by Chen-Han Hsiao
type "git log" in your remote repository to see if it contains the newest commit. If not, you should check the configuration of you local repository to see the remote settings.
在远程存储库中键入“git log”以查看它是否包含最新的提交。如果没有,您应该检查本地存储库的配置以查看远程设置。
To see the changes in different type of your remote repository:
要查看不同类型的远程存储库中的更改:
A. If your remote repository is bare, you can find the files in the remote repository branches/ config description HEAD hooks/ info/ objects/ refs/
A. 如果你的远程仓库是裸的,你可以在远程仓库的分支/配置描述 HEAD hooks/info/objects/refs/ 中找到文件
after new commit is pushed, files in objects/ directory would changed.
推送新提交后,对象/目录中的文件将更改。
B. If your remote repository is non-bare, type "git checkout master" And "git status" in your remote repository to see the file status. See if some file has been modified or deleted.
B、如果你的远程仓库是非裸的,在你的远程仓库输入“git checkout master”和“git status”查看文件状态。查看某个文件是否已被修改或删除。
回答by shaneonabike
One other issue could be that while you might have used
另一个问题可能是,虽然您可能已经使用过
git add your-dirs
git 添加你的目录
You have to remember to commit the files within directories
您必须记住提交目录中的文件
git commit -m'Add your message' your-dir/*
git commit -m'添加你的消息' your-dir/*
Then add a git push in order to push it to your remote
然后添加一个 git push 以将其推送到您的遥控器
回答by shaneonabike
I just experienced a similarly frustrating occurrence of not seeing my change replicated on github. As a new git user, just getting used to the using the system, I created a folder on my computer, added it, committed it, pushed it - no change. I considered the possibility that I cannot push an empty directory, so I created an empty file in the directory and then repeated the above steps. All better, the change was instantly mirrored in my github repo.
我刚刚经历了同样令人沮丧的情况,即没有看到我的更改在 github 上复制。作为一个新的 git 用户,刚刚习惯使用系统,我在我的电脑上创建了一个文件夹,添加它,提交它,推送它 - 没有改变。我考虑了无法push空目录的可能性,所以在目录下创建了一个空文件,然后重复上面的步骤。更好的是,更改立即反映在我的 github 存储库中。