Solved

first few commands for git?

Posted on 2011-09-08
6
436 Views
Last Modified: 2012-08-13
Hi Experts,

I just did a git svn clone command from my svn repository.  I then worked a bit on the code and have some changes locally that I would like to start another git branch for, before adding these changed files to the git branch.  Could you help me with:
1-  command to create the new branch (considering that I have local mods after initial clone)
2-  add the modified files (since the initial clone)
3-  commit to the branch
4-  revert to normal svn branch.

Thank you very much!
Mike
0
Comment
Question by:thready
  • 3
  • 3
6 Comments
 
LVL 1

Author Comment

by:thready
ID: 36507922
I tried the git extensions for explorer - I tried "Create branch" and I get an error that says:

The following untracked working tree files would be overwritten by checkout (with a whole bunch of files).

Why would they be overwritten?
0
 
LVL 40

Expert Comment

by:evilrix
ID: 36510550
1-  command to create the new branch (considering that I have local mods after initial clone)

Heh. The general idea is you back the branch first :)

First of all commit any changes to your current (master?) branch

git commit -am "some message"

Then create and checkout your new branch
git checkout -b <branchname>

Your new branch will now be in sync with the previous branch. You can now return back to the previous (master?) branch and reset it back to the original pre-commit state and your new branch will have all the changes.

git checkout <oldbranch>
git reset --hard HEAD^

2-  add the modified files (since the initial clone)

To add all the new files just do

git add .

To add a specific file

git add <filepath>

3-  commit to the branch

git commit -am "commit message"

4-  revert to normal svn branch.

If you mean revert back to the state that reflects the svn repo but the way you'd normally do this is to reset back to the origin/<branch> tag. Assuming you are in master of a tracking branch and you want to reset back to the remote master state you'd do this...

git reset --hard origin/master

Not sure if that will work from an svn repo though as I don't think a direct clone counts as a tracking branch. If that isn't the case then you could look at the git log and find the revision id you want to revert to, something like...

git log

find the revision id and then

git reset --hard <revision-id>
0
 
LVL 40

Accepted Solution

by:
evilrix earned 500 total points
ID: 36510618
>> I tried the git extensions for explorer - I tried "Create branch" and I get an error that says:
I gave up on all the GUI tools for git (except those that come with it) as they are all problematic. They hide the power (and the fact that doing everything from the command line is pretty trivial) of git behind buttons that often obfuscate what's happening. If  you really want to use a GUI I'd recommend Git Extensions.

http://code.google.com/p/gitextensions/

There is also a Tortoise-Git but I didn't really find that at all useful when working with Git.

>> The following untracked working tree files would be overwritten by checkout (with a whole bunch of files).
>> Why would they be overwritten?

There are 2 ways to create a new branch

git branch <branchname>
git checkout -b <branchname>

The former creates the branch but leaves you in the current branch, whereas the latter will change you to the new branch. If you perform the latter (and it sounds like this is what your GUI is doing) and you have uncommited changes they would get lost (since they don't exist in the new branch since it would be a reflection of only commited changes). For that reason you either need to commit of stash before changing to a new branch.

http://book.git-scm.com/4_stashing.html

You might find this tutorial helpful: http://git.or.cz/course/svn.html

Also, another GUI I quite like is SmartGIT. It's not free for commercial use though... but it isn't too bad and if you're just working on your own stuff it's worth looking at.

http://www.syntevo.com/smartgit/index.html

That all said, learn to use the git command line tool. Unlike the svn command line too (which is just painful) the git one is actually quite simple and is generally a lot quicker to use. Also, you get more of a feel for what you're actually doing so things generally make a lot more sense when you get an error :)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Closing Comment

by:thready
ID: 36537950
Thanks a lot - I'm about to start using it finally.  My fingers are crossed!  :o)
0
 
LVL 40

Expert Comment

by:evilrix
ID: 36538593
Heh... good luck -- I doubt you'll ever consider using SVN again once you've started using Git in anger. I never could!
0
 
LVL 1

Author Comment

by:thready
ID: 36538602
thanks evilrix - I have another question that I think you'd get super easy points with if you're interested:

http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_27308409.html#a36538575

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Poor Man's .NET Framework Certification 2 47
Problem with SqlConnection 4 160
How to print into std::string like sprintf using C++11? 12 50
What is sub-make ? 2 39
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now