英文:
Git is outputting `Your branch is up to date with 'origin/main'.` when trying to commit, but changes are being made
问题
我最近设置了一台新电脑(Mac M1),下载/设置了VSCode,现在在处理一个我正在开发的存储库时遇到了问题。
我的目标只是在进行更改时能够推送到GitHub上的存储库。然而,我遇到了一个问题,当我尝试提交时,我的终端输出说我的分支是最新的。
当我尝试提交代码更改到GitHub存储库时,我首次意识到了这个问题(首先运行 git add .
然后运行 git commit -m "...".
尽管在之前已经工作过(比如在初始化存储库时),但这一次出现了一条消息:
在分支 main 上
您的分支与 'origin/main' 最新。
无需提交,工作树干净
然而,这些更改并未出现在GitHub存储库中。
我尝试了什么:
一篇帖子 提到可能是我的 "本地分支不知道远程分支",建议运行 git branch --set-upstream-to origin/master
(或者在我的情况下 git branch --set-upstream-to origin/main
)。运行后,输出显示 分支 'main' 设置为跟踪 'origin/main'。
但当我再次尝试运行 git commit -m "...".
时,我仍然得到了之前关于我的分支是最新的相同输出(尽管实际情况并非如此)。
另一篇帖子 建议尝试创建一个新的存储库并推送现有代码。我尝试了几种变化:
- 运行
m -rf .git/
,然后在相同文件夹中初始化存储库,但推送到相同的位置。 - 删除文件夹,然后从GitHub克隆一个新的,并进行新的提交。
- 初始化一个新的GitHub存储库并推送代码。
虽然每种方法的第一次提交都有效,但随后的提交返回了与最初问题相同的输出。
这篇文章 建议运行 git remote add origin https://github.com/.../...
但在我运行并尝试提交更改后,结果对我来说是相同的输出。
另一篇文章 建议我的 "本地副本... 可能与您的远程来源最新也可能不是",并建议运行 git fetch
,但运行 git status
后,它输出说一切都是最新的。
大多数其他文章和帖子都是这些变化的一些变体,而那些不是的我尽力去遵循,但没有看到任何变化。
我期待的是:
我期待着有变化可以提交,当我推送时,GitHub存储库会反映出这些变化。
英文:
So I set up a new computer recently (Mac M1), downloaded / setup vscode and am now having trouble with a repo I'm working on.
My goal is just to be able to push to the repository on github when changes are made. However I've been running into a problem where when I try to commit, my terminal outputs that my branch is up to date.
I first realized the problem when I tried to committing a change in the code to the github repo (first running git add .
and then running git commit -m "..."
. While it had worked previously (such as when initializing the repository), this time there was a message:
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean
The changes however were not on the github repository.
What did I try:
One post mentioned it might be that my "local branch doesn't know about the remote branch" and to run git branch --set-upstream-to origin/master
(or in my case git branch --set-upstream-to origin/main
). After running that, the output was branch 'main' set up to track 'origin/main'.
but when I tried to run git commit -m "..."
again I still got the same output as before about my branch being up to date (despite this not being the case).
Another post suggested to try to make a new repo and push the existing code. I tried a few variations of this
- Running
m -rf .git/
and then initializing the repo in the same folder but pushing to the same 2. Deleting the folder and cloning a new one from github and then making a new commit - Initializing a new github repo and pushing the code.
While the first commit worked for each of these ways, following commits returned the same output as the initial problem.
This article suggested to run git remote add origin https://github.com/.../...
but resulted in the same output for me after running and trying to commit the changes.
Another article suggested my "local copy... may or may not be up-to-date with your origin remote" and to run git fetch
but after running git status
again, it outputted that everything was up to date.
Most other articles and posts were some variation of these and the ones that weren't I tried my best to follow but didn't see any changes.
What was I expecting:
I was expecting for there to be changes to commit and that when I pushed, the github repository would reflect those changes.
答案1
得分: 1
除了 git status
,还要仔细检查以下命令的输出:
git remote -v
git branch -avv
git log --oneline --decorate --graph --all --branches
最后一个命令应该会显示:
- 本地 HEAD 的位置
- origin/main 的位置
如果这些提交尚未被推送,你将看到它们是否与一个分支关联(或者如果你处于分离的HEAD状态)。
英文:
In addition of git status
, double-check the output of:
git remote -v
git branch -avv
git log --oneline --decorate --graph --all --branches
The last one should show you:
- where is your local HEAD
- where is origin/main
You will see what has not yet been pushed, if if those commits are associated to a branhc (or if you are in a detached HEAD mode)
答案2
得分: 0
解决方案非常愚蠢。
我刚刚在我的新电脑上下载了VSCode,从未打开自动保存功能。因此,Git不知道我所做的更改,所以它输出我的分支是最新的(而文本编辑器似乎显示不同)。
英文:
The solution was very silly.
I had just downloaded vscode to my new computer and never turned autosave on. Because of this, git wasn't aware of the changes I was making and so it outputted that my branch was up to date (when the text editor seemed to show otherwise).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论