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?
If you just want to throw away the changes and revert to the last commit (the one you wanted to share):
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
remove the specified files from the next commit
git reset HEAD^ --soft
(Save your changes, back to last commit)git reset HEAD^ --hard
(Discard changes, back to last commit)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
I resolved this by just running a simple:
Nothing more. Now it's showing:
You cannot push anything that hasn't been committed yet. The order of operations is:
git add
- this stages your changes for committinggit commit
- this commits your staged changes locallygit push
- this pushes your committed changes to a remoteIf 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.
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.
In other words:
add
andcommit
are local operations,push
,pull
andfetch
are operations that interact with a remote.Since there seems to be an official source control workflow in place where you work, you should ask internally how this should be handled.