Elitmiar
Elitmiar

Reputation: 36879

GIT not commiting changes

I'm a total newcomer to GIT and repositories, so I ran into a problem and dont know what I did wrong

I'm not sure if I'm doing something wrong but I did the following

  1. I cloned the GIT repo to my logo machine
  2. I made some changes to the server itself via vim to see if what I wanted to do actually works, which did work "Probably this is where my mistake is"
  3. I the did a git pull in my local repo to ensure I have all the latest commits
  4. Then I made my changes locally, via git status on local it showed me that two files have been modified. So then I tried git push to push my changes up, and this showed my all where already up to date
  5. I then committed my files locally git commit and then git push, now git push actually did something,
  6. When I logged into the server did a git status, it showed me 2 files where modified, I then went to git log which showed my commits on local, I then re-commited the files server side and my changes just did not take effect.
  7. I the did a git reset --hard HEAD but still my changes did not show,

What am I doing wrong?

Upvotes: 1

Views: 188

Answers (2)

Matthew Flaschen
Matthew Flaschen

Reputation: 285027

It sounds like you're pushing to a repository with a working tree attached. To avoid problems, it's better to push to only bare repositories, those created with git clone --bare (or equivalent).

If you do push to non-bare repos, anyway, you will have to do the following commands on the server. This will lose all local (non-committed) changes.

git reset --hard HEAD
git checkout -f

Upvotes: 1

patthoyts
patthoyts

Reputation: 33223

You have to add your changes to the index and then commit them.

git add modified_file
git add other_file
git commit -m "message"

The use of the index to construct the next commit makes it possible to do things like add only some of the changes in a modified file (see git-gui's Stage hunk menu option). Once the index has the correct set of modifications then git commit forms a commit out of that. git push is used to send commits that your repository contains that are not present in the upstream repository. So if there are no new commits on your local side, nothing will be done.

Upvotes: 0

Related Questions