All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: Basic Git Questions
@ 2010-12-20 19:21 George Spelvin
  2010-12-21  2:59 ` Adam Kellas
  0 siblings, 1 reply; 5+ messages in thread
From: George Spelvin @ 2010-12-20 19:21 UTC (permalink / raw)
  To: paragkalra; +Cc: git, linux

> 1. I generally add the files in my working directory using "git add
> .". But sometimes you want to add all the files except 1 or 2 file. Is
> there a shortcut way we can tell git to add all the files but exclude
> a particular file.

Others have pointed out the general techniques, but a few additional
things that may be useful in some situations:

1) .gitignore.  If the files are such that you never want git to pay
   attention to them, you can add them to the .gitignore file.
2) "git add -u".  This adds only files that git is already tracking,
   and ignores truly new files.
3) "git add -i".  This lets you pick the files to be added from a list.
4) "git gui".  This lets you click on the files to be added.
   It's my preferred way to do a selective commit.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Basic Git Questions
  2010-12-20 19:21 Basic Git Questions George Spelvin
@ 2010-12-21  2:59 ` Adam Kellas
  0 siblings, 0 replies; 5+ messages in thread
From: Adam Kellas @ 2010-12-21  2:59 UTC (permalink / raw)
  To: git

On 12/20/2010 2:21 PM, George Spelvin wrote:
> 1) .gitignore.  If the files are such that you never want git to pay
>     attention to them, you can add them to the .gitignore file.

My own preferred pattern is to flip the default: I put a '*' in 
.gitignore and use "add -f" when I want files tracked.

AK

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Basic Git Questions
  2010-12-19 23:08 ` Konstantin Khomoutov
@ 2010-12-19 23:15   ` Thomas Rast
  0 siblings, 0 replies; 5+ messages in thread
From: Thomas Rast @ 2010-12-19 23:15 UTC (permalink / raw)
  To: Parag Kalra; +Cc: Konstantin Khomoutov, git

Konstantin Khomoutov wrote:
> > 2. Also sometime when the code is committed, I realize that I have
> > forgot to change or add a file. Is there a way we can we commit a file
> > to existing commit number with git log showing only the old git commit
> > number and not creating a new one for the last commit.
> `git commit --amend` does exactly that -- amends the last commit
> (pointed by the HEAD ref).

Let me add that you can fundamentally not edit any git object in any
way without its ID (hash, sha1, whatever you call it) changing.  All
methods of "changing" commits, like amend, rebase, filter-branch
etc. always create a new object.  The trick is that, especially with
amend, the branch is also changed to point to the new one, so unless
you have already merged or pushed that commit, this is as close to
"changing" as it gets.

Tv put this more eloquently as: "you can never change; you can only
rewrite and forget".

If you *have* merged or pushed the commit, you shouldn't rewrite
history.  It's not that hard to fix up your local merges, but if you
have pushed the history and others have started working with it, it's
*very* annoying for them.

-- 
Thomas Rast
trast@{inf,student}.ethz.ch

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Basic Git Questions
  2010-12-19 22:32 Parag Kalra
@ 2010-12-19 23:08 ` Konstantin Khomoutov
  2010-12-19 23:15   ` Thomas Rast
  0 siblings, 1 reply; 5+ messages in thread
From: Konstantin Khomoutov @ 2010-12-19 23:08 UTC (permalink / raw)
  To: Parag Kalra; +Cc: git

On Sun, Dec 19, 2010 at 02:32:41PM -0800, Parag Kalra wrote:

> 1. I generally add the files in my working directory using "git add
> .". But sometimes you want to add all the files except 1 or 2 file. Is
> there a shortcut way we can tell git to add all the files but exclude
> a particular file.
Use `git add .` to add all the files and then `git rm --cached` those
one or two you don't need to be committed. See the git-rm manual for
details.

> 2. Also sometime when the code is committed, I realize that I have
> forgot to change or add a file. Is there a way we can we commit a file
> to existing commit number with git log showing only the old git commit
> number and not creating a new one for the last commit.
`git commit --amend` does exactly that -- amends the last commit
(pointed by the HEAD ref).
If you need to modify a commit older than the last one, you have to
rebase a part of the branch starting with that commit and then edit
(amend) that commit during the rebasing process. This might have
certain caveats though, so refer to git-rebase manual.
More on rebasing can be found in various pieces of documentation and
books listed at http://git-scm.com/documentation

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Basic Git Questions
@ 2010-12-19 22:32 Parag Kalra
  2010-12-19 23:08 ` Konstantin Khomoutov
  0 siblings, 1 reply; 5+ messages in thread
From: Parag Kalra @ 2010-12-19 22:32 UTC (permalink / raw)
  To: git

Hi,

1. I generally add the files in my working directory using "git add
.". But sometimes you want to add all the files except 1 or 2 file. Is
there a shortcut way we can tell git to add all the files but exclude
a particular file.

2. Also sometime when the code is committed, I realize that I have
forgot to change or add a file. Is there a way we can we commit a file
to existing commit number with git log showing only the old git commit
number and not creating a new one for the last commit.

Cheers,
Parag

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-12-21  3:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-20 19:21 Basic Git Questions George Spelvin
2010-12-21  2:59 ` Adam Kellas
  -- strict thread matches above, loose matches on Subject: below --
2010-12-19 22:32 Parag Kalra
2010-12-19 23:08 ` Konstantin Khomoutov
2010-12-19 23:15   ` Thomas Rast

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.