Your branch is ahead of 'origin/master' by 1 commit

匿名 (未验证) 提交于 2019-12-03 02:42:02

问题:

I'm a little new to Git, and I'm hoping somebody can explain what this message means exactly, in my scenario.

To give you some background information, this is what I've done:

  • I've cloned a repo to my local computer, created a new branch and made some changes. Then, I added these changes to the staging/tracked area, committed my changes, and then pushed everything to GitHub.

Now, when I run:

git status 

I get: "Your branch is ahead of 'origin/master' by 1 commit."

It doesn't make sense to me because I've not made any changes that I'm aware of. If I run:

git diff 

I don't get anything. I don't get a list of tracked files that I need to commit.

What is happening?

Note: I work with a team, so I'm waiting for them to review my code and possibly merge and incorporate the changes to the Master branch.

回答1:

This means that you have committed changes to the repository local to your machine. Those commits do not exist in the repository that you have cloned from. That message is a reminder that your repository has things in it that do not exist anywhere else.

To make git "happy" you need to push your changes somewhere (usually from where you cloned from)

run git push origin master to resolve.



回答2:

It's possible that you only pushed the master branch but not your new branch. You can do this with:

git push -u origin <branch>



回答3:

Looks like you have set the current branch's remote tracking branch to origin/master and you have something in the branch which is not there in the origin/master branch.

You can verify the remote tracking branch by running,

git branch -vv 

Once done, you can check the commits which are not in the remote branch by,

git cherry -v origin/master 

Or if you want to see the difference, just run,

git diff origin/master 


回答4:

So you have cloned, created a new branch, made some changes and committed them to your branch. I assume you have used

git push -u origin <your_branch_name> 

Since you have made a new commit to your branch, it says 'your branch is ahead of master by 1 commit'.

Since you have committed the changes and pushed it to remote, you cannot view the differences in the files using git diff and cannot view your modified files using git status, since they are not in the staging area anymore.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!