I just started playing around with git (coming from SVN), and I’m sure I’m not thinking of this in the right way – I cloned a repository from github, and removed tags from it and added my own. But when I do a git status or git diff, it says there’s nothing to commit. Shouldn’t it be comparing against the github project I cloned from? I’m thinking of this the wrong way I know, but maybe someone can help me wrap my head around this.
Share
You are looking at this the wrong way.
What you need to do is forget what you know about svn. In svn, you have a repository, which is located on a server. You change your files and commit a delta of them.
In git however, you have a repository on your computer. If you want, you also have one on github. Someone else working on your project would also have a repository of her own. Notice that I said repository. Yes! Repository! Which means you have all the history right there in your computer. You can commit, create tags, branch, merge, everything on your own computer without touching anything in github.
Welcome to a distributed version control system.
Another difference with svn is that, you don’t see the commits as deltas, but you see each commit as the whole set of files from your project. So for example weird merge of svn (where you say merge the difference between this revision and that revision to my files) doesn’t exist in git. You just merge with that snapshot of the project.
Commit then means to commit changes to your files to your own repository. Creating tags is another process. A process that doesn’t change your files (unlike svn where creating a tag means copying files). A tag in git is just a pointer to a specific commit!
So what you want to do is two different things:
Commit: commit changes to your repository. The command is
you can add files to the commit with
git add some_fileand commit only part of changes to your source code (which is something you don’t get with svn). Or if you want to commit all changed files, you add the-aoption.Push: push sends to another repository, let’s say a remote repository, named origin (which points to github), all that you have in your own repository. This includes all commits, and if you specify
-tagsalso the tags you created. For example:Alternatively, when you want to update your repository, from origin, you would first:
Fetch: update your repository to the remote one. The famous:
this brings all the new commits and tags that exist in
originbut not your local repository.Merge: Then update your master branch to that of the remote’s:
So back to your case, no there is nothing to commit, but there are tags that you need to push. One last thing to tell you is that, when you remove tags, you remove them only from your own repository. To remove it from the remote:
Understanding this syntax requires a bit more advanced tutorial on git push, but for now accept this. Note that removing tags is strongly frowned upon. This is because if someone downloads that tag and starts using it and get dependent on it, she can’t find it again later if she needs it. So, when creating tags, make sure the software/library is they way you want it to be.