views:

94

answers:

3
+3  Q: 

Using git properly

I have been reading up and trying Git for the last few days and I have one more thing that i can't seem to find good information on.

I read that with Git it's common to set up a public and a private repository clone on each developer's machine that way the developer can do private commits as many times as he/she wants and then only push to the public repository once they are satisfied with the changes.

I would like to know two things:

1-how do i set up a system such as the above (while using a centralized type approach (repository created with --bare).

2-I want to be able to make as many commits to my private repository as I want with any commit message and not have these messages (or revisions) show up when i push my changes to the public repository or the bare repository). Ie. i want my public changes to be committed as one lump sum with a single message.

Thanks!

+2  A: 

git rebase is your friend

This answer to the question, what-are-your-favorite-git-features-or-tricks specifically talks about your situation

Jason Watts
That's exactly what i needed but i have one more question, in the example he uses git rebase -i HEAD~3can i do git rebase -i <some tag>to avoid having to remember how many commits i made to what files for the last set of changes, where tag is a tag of the source tree before i started making any commits.
Coder
@Coder: Yes, most git commands accept many different kinds of identifiers, such as SHA1 commit ids, tags, relative identifiers (like `HEAD~3`), dates, etc. See [Git Treeishes](http://book.git-scm.com/4_git_treeishes.html) for the full set.
Greg Hewgill
http://book.git-scm.com/4_rebasing.htmlthis is from the official git book. i am not sure of the exact answer to your question, but you should setup a dummy repository and test it out until you get it working right.
Jason Watts
+1  A: 

There are a few ways to set up a Git "central" server, as described in the FAQ, mainly via git-daemon, over HTTP or via an existing SSH server (if it's on a Linux box, you can share a repository by setting unix groups appropriately and giving group permissions). Alternatively, you can use existing services like GitHub.

If you want to push a number of local commits as a single commit, you can "squash" those commits, with git merge or git rebase -i (interactive). I find it easier to do with git rebase -i. You need to give a hash or identifier for a previous commit (from which you may want to merge) as an argument. Then, you'll get a editor with something like this:

pick 0000001 Fixed big bug 1
pick a000002 Fixed big bug 2
pick dae3124 Fixed big bug 3
pick 3554abc Fixed big bug 4

# Rebase 5cea2cd..8963229 onto 5cea2cd
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#

You can then edit this file to have something like this:

pick 0000001 Fixed big bug 1
squash a000002 Fixed big bug 2
squash dae3124 Fixed big bug 3
pick 3554abc Fixed big bug 4

Once you save the file, Git will offer you to edit the log messages of the commits you squash into one message. Effectively, you'll have merged 0000001, a000002 and dae3124 into "Fixed big bugs 1, 2 and 3." for example. (You could use fixup too.) You log will then be:

0014234 Fixed big bugs 1, 2 and 3.
3554abc Fixed big bug 4

(Of course, the result hash of the merged commit will look nothing like the hashes of the commits it comes from.)

Once you've done that locally, you can push that branch to the remote public repository.

Bruno
+1  A: 

Greetings,

I recommend reading this free book on git. ProGit book. It gives a very good grounding in all git's functions.

To solve your immediate problem, I'll direct you to this page

http://toolmantim.com/thoughts/setting_up_a_new_remote_git_repository

I use this process in work. Great workflow. I recommend it.

Hope this helps.

kobrien