reverting changes

2013-04-04 Thread Thiago Farina
Hi,

When I want to revert a change to a file that is already committed
what is the best way?

The way I found was:

$ git checkout HEAD /path/to/my/file
$ git reset HEAD /path/to/my/file

Is this the canonical/best way or there other (easier-faster) ways?

Thanks,
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: reverting changes

2013-04-04 Thread Junio C Hamano
Thiago Farina tfrans...@gmail.com writes:

 When I want to revert a change to a file that is already committed
 what is the best way?

 The way I found was:

 $ git checkout HEAD /path/to/my/file
 $ git reset HEAD /path/to/my/file

 Is this the canonical/best way or there other (easier-faster) ways?

If the issue you are solving is:

  What I committed to path/to/my/file is in good state.  I then
  edited path/to/my/file but it turns out that I do not like what I
  did.  I want the version I committed back (perhaps to start over,
  perhaps to do nothing further).

then you can checkout the path out of the commit, i.e.

git checkout HEAD path/to/my/file

is the canonical and best way.

But I am not sure if that is what you are asking with want to
revert a change to a file that is already commited.  It can be
read:

I started from one state, made changes and have already
committed them.  These changes were bad ones that I regret, and
I do not want them.

and if so, git checkout HEAD path/to/my/file will happily grab the
state after these bad changes are applied out of the commit.
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


three questions: proper forum? reverting changes to the working directory

2012-11-08 Thread McKown, John
1) is this the proper forum for asking general git usage questions, such as 
how to? If not, what is?

2) I am unsure that I did things the proper way. I have a git maintained 
subdirectory. I made some changes and saved them in the working directory, but 
did not git add or git commit them. I then decided that I really messed up 
what I was doing (basically reformatting some source code). So to revert the 
changes back to what was last committed, I did a git reset --hard HEAD. I 
think this is the proper way. But I picked up that command in the section of 
the documentation which was talking about abandoning a git merge attempt. 
What I did worked, but is it the proper way? If not, what is? 

3) More generically, suppose I have a file in my working directory that I want 
to put back the way it was n commits ago. The best that I can see, so far, is 
git show HEAD~n:file |file, replacing the n and file with appropriate 
values. 

-- 
John McKown
Systems Engineer IV
IT

Administrative Services Group

HealthMarkets(r)

9151 Boulevard 26 * N. Richland Hills * TX 76010
(817) 255-3225 phone *
john.mck...@healthmarkets.com * www.HealthMarkets.com

Confidentiality Notice: This e-mail message may contain confidential or 
proprietary information. If you are not the intended recipient, please contact 
the sender by reply e-mail and destroy all copies of the original message. 
HealthMarkets(r) is the brand name for products underwritten and issued by the 
insurance subsidiaries of HealthMarkets, Inc. -The Chesapeake Life Insurance 
Company(r), Mid-West National Life Insurance Company of TennesseeSM and The 
MEGA Life and Health Insurance Company.SM


--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html



RE: three questions: proper forum? reverting changes to the working directory

2012-11-08 Thread McKown, John
Well, a message I read after posting seems to have answered question #3. I'll 
look at git checkout, which ignorant me thought was only used to change 
branches.

-- 
John McKown
Systems Engineer IV
IT

Administrative Services Group

HealthMarkets(r)

9151 Boulevard 26 * N. Richland Hills * TX 76010
(817) 255-3225 phone *
john.mck...@healthmarkets.com * www.HealthMarkets.com

Confidentiality Notice: This e-mail message may contain confidential or 
proprietary information. If you are not the intended recipient, please contact 
the sender by reply e-mail and destroy all copies of the original message. 
HealthMarkets(r) is the brand name for products underwritten and issued by the 
insurance subsidiaries of HealthMarkets, Inc. -The Chesapeake Life Insurance 
Company(r), Mid-West National Life Insurance Company of TennesseeSM and The 
MEGA Life and Health Insurance Company.SM


 -Original Message-
 From: git-ow...@vger.kernel.org [mailto:git-ow...@vger.kernel.org] On
 Behalf Of McKown, John
 Sent: Thursday, November 08, 2012 8:26 AM
 To: 'git@vger.kernel.org'
 Subject: three questions: proper forum?  reverting changes to the
 working directory
 
 1) is this the proper forum for asking general git usage questions,
 such as how to? If not, what is?
 
 2) I am unsure that I did things the proper way. I have a git
 maintained subdirectory. I made some changes and saved them in the
 working directory, but did not git add or git commit them. I then
 decided that I really messed up what I was doing (basically
 reformatting some source code). So to revert the changes back to what
 was last committed, I did a git reset --hard HEAD. I think this is
 the proper way. But I picked up that command in the section of the
 documentation which was talking about abandoning a git merge attempt.
 What I did worked, but is it the proper way? If not, what is?
 
 3) More generically, suppose I have a file in my working directory that
 I want to put back the way it was n commits ago. The best that I can
 see, so far, is git show HEAD~n:file |file, replacing the n and
 file with appropriate values.
 
 --
 John McKown
 Systems Engineer IV
 IT
 
 Administrative Services Group
 
 HealthMarkets(r)
 
 9151 Boulevard 26 * N. Richland Hills * TX 76010
 (817) 255-3225 phone *
 john.mck...@healthmarkets.com * www.HealthMarkets.com
 
 Confidentiality Notice: This e-mail message may contain confidential or
 proprietary information. If you are not the intended recipient, please
 contact the sender by reply e-mail and destroy all copies of the
 original message. HealthMarkets(r) is the brand name for products
 underwritten and issued by the insurance subsidiaries of HealthMarkets,
 Inc. -The Chesapeake Life Insurance Company(r), Mid-West National Life
 Insurance Company of TennesseeSM and The MEGA Life and Health Insurance
 Company.SM
 
 
 --
 To unsubscribe from this list: send the line unsubscribe git in the
 body of a message to majord...@vger.kernel.org More majordomo info at
 http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: three questions: proper forum? reverting changes to the working directory

2012-11-08 Thread Konstantin Khomoutov
On Thu, 8 Nov 2012 08:26:22 -0600
McKown, John john.mck...@healthmarkets.com wrote:

 1) is this the proper forum for asking general git usage questions,
 such as how to? If not, what is?

This list is okay for the general usage questions.
But since it's the place where the development questions are discussed
as well, and patches get posted, you might find its signal-to-noise
ratio to be not very convenient for a casual user.

For mere mortals, we have another list, git-users, hosted on Google
Groups [1].  It deals only with problems Git newbies have with Git.

 2) I am unsure that I did things the proper way. I have a git
 maintained subdirectory. I made some changes and saved them in the
 working directory, but did not git add or git commit them. I then
 decided that I really messed up what I was doing (basically
 reformatting some source code). So to revert the changes back to what
 was last committed, I did a git reset --hard HEAD. I think this is
 the proper way. But I picked up that command in the section of the
 documentation which was talking about abandoning a git merge
 attempt. What I did worked, but is it the proper way? If not, what
 is?

Yes, that was the proper way.  A failed Git merge attempt could be
considered as just another case of a messed-up state of the work tree
and the index.

You might want to read the Reset Demystified [2] document for a
friendly descriptions of how different ways to invoke `git reset`
affect the repository, the index and the work tree.
 
 3) More generically, suppose I have a file in my working directory
 that I want to put back the way it was n commits ago. The best that
 I can see, so far, is git show HEAD~n:file |file, replacing the
 n and file with appropriate values.

`git checkout` is able to fetch specific versions of the specified
files if called like this:

$ git checkout HEAD~n -- filename 

1. http://groups.google.com/group/git-users/
2. http://git-scm.com/2011/07/11/reset.html
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: three questions: proper forum? reverting changes to the working directory

2012-11-08 Thread Andy Hawkins
Hi,

In article a6b9336cdb62bb46b9f8708e686a7ea0115baa1...@nrhmms8p02.uicnrh.dom,
   McKown, Johnjohn.mck...@healthmarkets.com wrote:

 1) is this the proper forum for asking general git usage questions, such
 as how to?  If not, what is?

I'd say that here is fine. #git on freenode is also a good source of advice.

 2) I am unsure that I did things the proper way. I have a git maintained
 subdirectory.  I made some changes and saved them in the working
 directory, but did not git add or git commit them.  I then decided
 that I really messed up what I was doing (basically reformatting some
 source code).  So to revert the changes back to what was last committed, I
 did a git reset --hard HEAD.  I think this is the proper way.  But I
 picked up that command in the section of the documentation which was
 talking about abandoning a git merge attempt.  What I did worked, but is
 it the proper way?  If not, what is?

The easiest answer to this is run 'git status'. It'll list the files in
various states, and tell you how to undo the changes.

Andy

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html