My understanding of git add is that you’re basically saying to your local git repo “Yes, I’m sure I want to make these changes.”
My understanding of git commit is to actually save the changes to your local HEAD branch. At this point they are actually in version control, but are only local to your instance of git.
My understanding of git push is to propagate your saved (committed) changes to the master repo, so other developers (or perhaps a CI build) can pull them down for themselves.
If anything that I have said so far is wrong or is misleading, please begin by correcting me. Assuming I’m correct in my understandings, I originally had a package in my Java project that looked like this:
com.myapp.server.servlets
FizzServlet
BuzzServlet
But then I decided to refactor the names and of a few things, as well as both adding & deleting some new files/packages:
com.myapp.server.servlet
FizzesServlet
WidgetServlet
com.myapp.server.servlet.impl
FizzesServletImpl
WidgetServletImpl
Overall, I account for 5 changes to this directory:
- Changed the name from “
com.myapp.server.servlets” to “com.myapp.server.servlet“ - Changed the name from “
FizzServlet” to “FizzesServlet“ - Deleted the
BuzzServletaltogether - Added a new
WidgetServlet - Added a new
com.myapp.server.servlet.implpackage with two child files
Do I have to do any sort of special command magic here, because I did so much refactoring, or can I just run something like git push * to push everything to GitHub? In the SVN Eclipse plugin, if I renamed a package or source file, and then tried committing that change, I would often lose the file altogether (locally) and have to restore from local history. Even then, I got burned far too many times to count and lost a lot of work. I’m hoping not to get the same experience with Git.
From the way you’re very careful about pushing, your understanding of
git pushis not quite complete.pushwill literally only push your commits to your remote — that means, it will copy the exact state that you saved in the commit(s) you have made since last pushing. In Git, every commit is a snapshot of all the files in a repository (it does in fact record all files, and not just the changes). So what you see locally after committing will be exactly what’s copied onto the remote when pushing.When you push, one of two things can happen:
git resetis used for this) or by fetching from the remote and (b) merging your local changes, thereby creating a merge commit which will indicate the diverging and re-converging of your history, or alternatively (c) rebasing onto the remote, to produce linear history.The conflict resolution case will take a bit more looking into, but the actions required are well-described in the Pro Git book (chapters Branching, Merging, Rebasing).
A conflict can only happen if someone else can push to your remote, or if you push to your remote from another computer. If you are working in a single-user single-computer scenario (at least for now), there will be no conflict when pushing.