Solved

first few commands for git?

Posted on 2011-09-08
6
435 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

743 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

11 Experts available now in Live!

Get 1:1 Help Now