{"thread":{"id":"22909","subject":"How do I get the correct modification status after running git diff?","startedAt":"2010-03-04T15:40:00Z","lastAt":"2010-03-04T16:39:00Z","messageCount":4,"participants":["jateeq","Michael J Gruber","Andreas Schwab"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"136154","messageId":"27782430.post@talk.nabble.com","threadId":"22909","inReplyTo":null,"subject":"How do I get the correct modification status after running git diff?","fromName":"jateeq","fromEmail":"jawad_atiq@hotmail.com","sentAt":"2010-03-04T15:40:00Z","receivedAt":"2010-03-04T15:40:00Z","isPatch":false,"sender":{"key":"jawad_atiq@hotmail.com","avatar":null},"body":"\nHello,\n\nI have added a new file to a working repository, and would like to run a\ndiff between the last commit and whatever is int he working tree, along with\nan identification of what kind of a modification it was. Currently, I am\nadding all files to the index with the -N option, and then running a git\ndiff --name-status. This works well for existing files that have been\nmodified or deleted, but fails if a file is rename or is added. Does anyone\nknow of the right way to do this? The commands I am using to add and diff\nnewly added files are as follows in the sequence shown.\n\nCommands:\necho \"this is a new file\" > file1.xml\ngit add -N .\ngit diff --name-status\n\nThe output is :\nM   file1.xml\n\nI want the status to show A for the newly added file (and R for renamed\nfiles but I don't know if that's possible).\n\nThank You,\nJawad.\n-- \nView this message in context: http://old.nabble.com/How-do-I-get-the-correct-modification-status-after-running-git-diff--tp27782430p27782430.html\nSent from the git mailing list archive at Nabble.com.\n"},{"id":"136155","messageId":"27782895.post@talk.nabble.com","threadId":"22909","inReplyTo":"27782430.post@talk.nabble.com","subject":"Re: How do I get the correct modification status after running git diff?","fromName":"jateeq","fromEmail":"jawad_atiq@hotmail.com","sentAt":"2010-03-04T16:11:13Z","receivedAt":"2010-03-04T16:11:13Z","isPatch":false,"sender":{"key":"jawad_atiq@hotmail.com","avatar":null},"body":"\nOk, so I think I know what I was doing wrong... i wasn't comparing the\nworking tree with the last commit (HEAD), although I still don't know what\nexactly I was comparing the working tree with. On reading the manual a\nlittle more carefully, I realised the command should have been: \n\ngit diff -M --name-status HEAD\n\nThis solves the problem of newly added files, but doesn't show 'R' for\nrenamed files even after I ask git to detect renamed files - just shows that\nthe renamed file was deleted (doesn't detect that the new renamed file was\nadded). So I would still appreciate some input here.\n\nRenaming flie:\nmv randomfile.xml random.xml\n\nDiffing:\ngit diff -M --name-status HEAD\n\nOutput:\nD      randomfile.xml\n\nThanks, \njawad\n\n-- \nView this message in context: http://old.nabble.com/How-do-I-get-the-correct-modification-status-after-running-git-diff--tp27782430p27782895.html\nSent from the git mailing list archive at Nabble.com.\n"},{"id":"136156","messageId":"4B8FE121.6040807@drmicha.warpmail.net","threadId":"22909","inReplyTo":"27782895.post@talk.nabble.com","subject":"Re: How do I get the correct modification status after running git diff?","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2010-03-04T16:34:41Z","receivedAt":"2010-03-04T16:34:41Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"jateeq venit, vidit, dixit 04.03.2010 17:11:\n> \n> Ok, so I think I know what I was doing wrong... i wasn't comparing the\n> working tree with the last commit (HEAD), although I still don't know what\n> exactly I was comparing the working tree with. On reading the manual a\n\nYou were comparing the working tree with the index (staging area).\n\n> little more carefully, I realised the command should have been: \n> \n> git diff -M --name-status HEAD\n> \n> This solves the problem of newly added files, but doesn't show 'R' for\n> renamed files even after I ask git to detect renamed files - just shows that\n> the renamed file was deleted (doesn't detect that the new renamed file was\n> added). So I would still appreciate some input here.\n> \n> Renaming flie:\n> mv randomfile.xml random.xml\n> \n> Diffing:\n> git diff -M --name-status HEAD\n> \n> Output:\n> D      randomfile.xml\n\ngit doesn't know about random.xml here, which you can change like so:\n\ngit add -N random.xml\n\nThen git diff -M --name-status HEAD will show the rename.\n\nAlternatively, you could have used \"git mv randomfile.xml random.xml\"\nwhich would have staged that move in the index already. (More exactly:\nthe content changes, not the move as such)\n\nMichael\n"},{"id":"136157","messageId":"m2lje8avob.fsf@igel.home","threadId":"22909","inReplyTo":"27782895.post@talk.nabble.com","subject":"Re: How do I get the correct modification status after running git diff?","fromName":"Andreas Schwab","fromEmail":"schwab@linux-m68k.org","sentAt":"2010-03-04T16:39:00Z","receivedAt":"2010-03-04T16:39:00Z","isPatch":false,"sender":{"key":"schwab@linux-m68k.org","avatar":"https://avatars.githubusercontent.com/u/2175493?v=4"},"body":"jateeq <jawad_atiq@hotmail.com> writes:\n\n> Renaming flie:\n> mv randomfile.xml random.xml\n>\n> Diffing:\n> git diff -M --name-status HEAD\n>\n> Output:\n> D      randomfile.xml\n\nrandom.xml is an untracked file, thus ignored.  You need to add -N it\nfirst.\n\nAndreas.\n\n-- \nAndreas Schwab, schwab@linux-m68k.org\nGPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5\n\"And now for something completely different.\"\n"}]}