'git - Your branch is ahead of 'origin/master' by 1 commit
I am newbie in git and I am working on git.
I added some files in 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?
Solution 1:[1]
git reset HEAD^ --soft
(Save your changes, back to last commit)
git reset HEAD^ --hard
(Discard changes, back to last commit)
Solution 2:[2]
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.
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
Solution 3:[3]
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
Solution 4:[4]
git reset HEAD^
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 master
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
Solution 5:[5]
git reset HEAD <file1> <file2> ...
remove the specified files from the next commit
Solution 6:[6]
connect to
remote origin/master
not
local master
and make a pull request.
Create a new branch base on remote master.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | |
Solution 3 | karlingen |
Solution 4 | Karan Singh |
Solution 5 | Bnjmn |
Solution 6 |