{"thread":{"id":"26105","subject":"Basic Git Questions","startedAt":"2010-12-19T22:32:41Z","lastAt":"2010-12-19T23:15:16Z","messageCount":3,"participants":["Parag Kalra","Konstantin Khomoutov","Thomas Rast"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"158373","messageId":"AANLkTiki2e4-YD0P9kb7g-WbLTPhAXQ22R2jCAXVtjN1@mail.gmail.com","threadId":"26105","inReplyTo":null,"subject":"Basic Git Questions","fromName":"Parag Kalra","fromEmail":"paragkalra@gmail.com","sentAt":"2010-12-19T22:32:41Z","receivedAt":"2010-12-19T22:32:41Z","isPatch":false,"sender":{"key":"paragkalra@gmail.com","avatar":null},"body":"Hi,\n\n1. I generally add the files in my working directory using \"git add\n.\". But sometimes you want to add all the files except 1 or 2 file. Is\nthere a shortcut way we can tell git to add all the files but exclude\na particular file.\n\n2. Also sometime when the code is committed, I realize that I have\nforgot to change or add a file. Is there a way we can we commit a file\nto existing commit number with git log showing only the old git commit\nnumber and not creating a new one for the last commit.\n\nCheers,\nParag\n"},{"id":"158375","messageId":"20101219230839.GM3264@localhost.localdomain","threadId":"26105","inReplyTo":"AANLkTiki2e4-YD0P9kb7g-WbLTPhAXQ22R2jCAXVtjN1@mail.gmail.com","subject":"Re: Basic Git Questions","fromName":"Konstantin Khomoutov","fromEmail":"flatworm@users.sourceforge.net","sentAt":"2010-12-19T23:08:39Z","receivedAt":"2010-12-19T23:08:39Z","isPatch":false,"sender":{"key":"flatworm@users.sourceforge.net","avatar":null},"body":"On Sun, Dec 19, 2010 at 02:32:41PM -0800, Parag Kalra wrote:\n\n> 1. I generally add the files in my working directory using \"git add\n> .\". But sometimes you want to add all the files except 1 or 2 file. Is\n> there a shortcut way we can tell git to add all the files but exclude\n> a particular file.\nUse `git add .` to add all the files and then `git rm --cached` those\none or two you don't need to be committed. See the git-rm manual for\ndetails.\n\n> 2. Also sometime when the code is committed, I realize that I have\n> forgot to change or add a file. Is there a way we can we commit a file\n> to existing commit number with git log showing only the old git commit\n> number and not creating a new one for the last commit.\n`git commit --amend` does exactly that -- amends the last commit\n(pointed by the HEAD ref).\nIf you need to modify a commit older than the last one, you have to\nrebase a part of the branch starting with that commit and then edit\n(amend) that commit during the rebasing process. This might have\ncertain caveats though, so refer to git-rebase manual.\nMore on rebasing can be found in various pieces of documentation and\nbooks listed at http://git-scm.com/documentation\n"},{"id":"158376","messageId":"201012200015.17203.trast@student.ethz.ch","threadId":"26105","inReplyTo":"20101219230839.GM3264@localhost.localdomain","subject":"Re: Basic Git Questions","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2010-12-19T23:15:16Z","receivedAt":"2010-12-19T23:15:16Z","isPatch":false,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Konstantin Khomoutov wrote:\n> > 2. Also sometime when the code is committed, I realize that I have\n> > forgot to change or add a file. Is there a way we can we commit a file\n> > to existing commit number with git log showing only the old git commit\n> > number and not creating a new one for the last commit.\n> `git commit --amend` does exactly that -- amends the last commit\n> (pointed by the HEAD ref).\n\nLet me add that you can fundamentally not edit any git object in any\nway without its ID (hash, sha1, whatever you call it) changing.  All\nmethods of \"changing\" commits, like amend, rebase, filter-branch\netc. always create a new object.  The trick is that, especially with\namend, the branch is also changed to point to the new one, so unless\nyou have already merged or pushed that commit, this is as close to\n\"changing\" as it gets.\n\nTv put this more eloquently as: \"you can never change; you can only\nrewrite and forget\".\n\nIf you *have* merged or pushed the commit, you shouldn't rewrite\nhistory.  It's not that hard to fix up your local merges, but if you\nhave pushed the history and others have started working with it, it's\n*very* annoying for them.\n\n-- \nThomas Rast\ntrast@{inf,student}.ethz.ch\n"}]}