git - 您的分支领先于 'origin/master' 1 次提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10169328/
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 - Your branch is ahead of 'origin/master' by 1 commit
提问by sam
I am newbie in git and I am working on git.
我是 git 的新手,我正在研究 git。
I added some files in git :
我在 git 中添加了一些文件:
git add <file1>
git add <file2>
then I wanted to push that for review, but mistakenly I did
然后我想推动,但我错误地做到了
git commit
so the files which I have changed don't go for reviews.
Now if I enter the command :
所以我更改过的文件不会被。
现在,如果我输入命令:
git status
it says
它说
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
nothing to commit (working directory clean)
I want to revert that commit and I want to push those files for review rather than commit. Can anyone let me know how I can do that?
我想恢复那个提交,我想推送这些文件进行而不是提交。谁能让我知道我该怎么做?
回答by tdammers
You cannot push anything that hasn't been committed yet. The order of operations is:
您不能推送任何尚未提交的内容。操作顺序为:
- Make your change.
git add
- this stages your changes for committinggit commit
- this commits your staged changes locallygit push
- this pushes your committed changes to a remote
- 做出改变。
git add
- 这会分阶段提交您的更改git commit
- 这会在本地提交您的分阶段更改git push
- 这会将您提交的更改推送到远程
If you push without committing, nothing gets pushed. If you commit without adding, nothing gets committed. If you add without committing, nothing at all happens, git merely remembers that the changes you added should be considered for the following commit.
如果不提交就推送,则不会推送任何内容。如果您提交而不添加,则不会提交任何内容。如果你在没有提交的情况下添加,什么都不会发生,git 只会记住你添加的更改应该考虑用于接下来的提交。
The message you're seeing (your branch is ahead by 1 commit) means that your local repository has one commit that hasn't been pushed yet.
您看到的消息(您的分支领先 1 个提交)意味着您的本地存储库有一个尚未推送的提交。
In other words: add
and commit
are local operations, push
, pull
and fetch
are operations that interact with a remote.
换句话说:add
和commit
是本地操作push
,pull
和fetch
是与远程交互的操作。
Since there seems to be an official source control workflow in place where you work, you should ask internally how this should be handled.
由于您工作的地方似乎有官方的源代码控制工作流程,您应该在内部询问应该如何处理。
回答by Juanito Fatas
git reset HEAD^ --soft
(Save your changes, back to last commit)
git reset HEAD^ --soft
(保存您的更改,回到上次提交)
git reset HEAD^ --hard
(Discard changes, back to last commit)
git reset HEAD^ --hard
(放弃更改,回到上次提交)
回答by Shep
If you just want to throw away the changes and revert to the last commit (the one you wanted to share):
如果您只想丢弃更改并恢复到最后一次提交(您想要共享的提交):
git reset --hard HEAD~
You may want to check to make absolutely sure you want this (git log
), because you'll loose all changes.
您可能需要检查以绝对确定您想要这个 ( git log
),因为您将丢失所有更改。
A safer alternative is to run
一个更安全的选择是运行
git reset --soft HEAD~ # reset to the last commit
git stash # stash all the changes in the working tree
git push # push changes
git stash pop # get your changes back
回答by karlingen
I resolved this by just running a simple:
我通过运行一个简单的来解决这个问题:
git pull
Nothing more. Now it's showing:
而已。现在显示:
# On branch master
nothing to commit, working directory clean
回答by OZI
git reset HEAD^
git重置头^
then the modified files should show up.
然后应该显示修改后的文件。
You could move the modified files into a new branch
您可以将修改后的文件移动到新分支中
use, git checkout -b newbranch git checkout commit -m "files modified" git push origin newbranch
使用, git checkout -b newbranch git checkout commit -m "files modified" git push origin newbranch
git checkout master
git结帐大师
then you should be on a clean branch, and your changes should be stored in newbranch. You could later just merge this change into the master branch
那么你应该在一个干净的分支上,你的更改应该存储在 newbranch 中。您可以稍后将此更改合并到主分支中
回答by Bnjmn
git reset HEAD <file1> <file2> ...
remove the specified files from the next commit
从下一次提交中删除指定的文件