Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git commit problems

Tags:

git

I just commited my working tree, added to index first, with "$git commit -m 'test'" I saved the stdout-put from this to a file and I see at the top of it that it says

# On branch master   # Changed but not updated:   # (use "git add/rm ..." to update what will be commited)   # (use "git checkout -- ..." to discard changes in working directory)"   

the problem is that my working tree is not being commited to the repo, and I have a feeling this has something to do with it

thanks

like image 298
deepblue Avatar asked Nov 16 '09 23:11

deepblue


People also ask

How can you fix a broken commit?

Simply edit the message right on the top line of the file, save, quit and you're done. Now let's say you've got a few commits to fix, or the commit that is broken is a few commits back. This process is a little more complex, but isn't too bad.

What does git commit do?

The git commit command captures a snapshot of the project's currently staged changes. Committed snapshots can be thought of as “safe” versions of a project—Git will never change them unless you explicitly ask it to.

How do I force a git commit?

The --force option for git push allows you to override this rule: the commit history on the remote will be forcefully overwritten with your own local history. This is a rather dangerous process, because it's very easy to overwrite (and thereby lose) commits from your colleagues.


2 Answers

Short answer:

git push -u origin master

Longer answer:

You're most likely trying to push commits to a branch that wasn't created yet - for example, on a newly created Github repository without the README file automatically created. By calling git push -u origin master, you specify both the remote that you need to push to (origin, which is usually the git default) and the branch (master, also default in typical cases). According to the git documentation:

-u, --set-upstream For every branch that is up to date or successfully pushed, add upstream (tracking) reference, used by argument-less git-pull(1) and other commands. For more information, see branch..merge in git-config(1).

This means that after a successful run of this command, from then on you'll be able to just use git push and git pull and it will default to origin master (with some exceptions).

like image 129
d33tah Avatar answered Sep 21 '22 16:09

d33tah


Before you commit a change, you must add it to the index first:

git add myfile git commit -m "test" 

Alternatively, you can work in a more SVN-like style and commit everything that is changed:

git commit -a -m "test" 

Or you can just add-and-commit a single file:

git commit myfile -m "test" 
like image 35
Will Robertson Avatar answered Sep 21 '22 16:09

Will Robertson