Why does git diff output show only names of changed files? - git-diff

I am facing a strange issue with git diff. The output of the command shows the files that were changed but does not show the exact change in the lines. It happens for both commands:
git diff
and
git diff --staged
Could anyone please suggest why this could be happening? Thanks!
I tried searching online but apparently, this is not a common issue and --name-only is the option to display only file names. In my case, the default output shows only modified file names.

Related

Git still tracks files in gitignore file

i am having the following problem with gitignore in windows (that i used in combination with vscode, if this info is important)
i tried a simple example in order not to complicate things.
my root folder contains:
maininterface.py
.gitignore
logs/dev.log
my gitignore file has only one line:
logs/
when typing git status i get the following:
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
logs/
maininterface.py
Am I missing something? the directory logs should not be in the untracked files.
I tried looking for solutions, many people suggest git rm --cached logs
This does not work for me, I get :
fatal: pathspec 'logs' did not match any files
(I also tried git rm --cached logs/dev.log , same problem)
BTW I haven't used git add on any of the files.
Thank you if you have a tip...
Check if your .gitignore file is free of parasite characters.
For example : a BOM at the beginning of the file would make git try to look for "{\xEF\xBB\xBF}logs".
[edit] : I had forgotten powershell writes in UTF-16 (or UCS-2) by default, you correctly found that, on top of a BOM, your file was actually encoded in UCS-2.
Problem solved.
with Notepad ++, it was the encoding issue...!
Thank you very much for the help

How to show all the files that have been changed?

I am working on a feature branch that branched off a develop branch. Now that I am ready to do a PR I just want to check which files have been changed. What git command will list all the files changed against the develop branch?
Git's diff command with the --stat option will show you a list of changed files without the detailed contents.
Use it like git diff --stat origin/develop feature_branch
If you want really basic results then you can instead use the --name-only option to just see the filenames and nothing else.
If you just want to see the file names, you can do
git diff --name-only develop
git diff develop
Often the PR tool will show you the differences too.
For example if Microsoft's Dev Ops (previously known as VSTS) when creating a pull request you can see the changes (and commits) at the bottom.

Committed PNG files to Git on Windows broke %PNG\r\n header

I added lots of PNG files to a Git repository on Windows, unfortunately with the setting text eol=lf to not commit Windows line breaks.
The problem is that the PNG header must be in the form %PNG\r\n and now all PNG images are in Git with the header %PNG\n and cannot be displayed like that.
I tried adding this line to .gitattributes:
*.png binary
But the files, although correct in the working directory, still show up as unchanged and git add does nothing.
I managed to fix single files with checking out the broken version and editing it manually but I hope there is a less tedious way.
How can I fix my repository without modifying the individual files?
I managed to solve it myself while writing down the question:
Remove all PNG files from repository but keep the working copies:
git rm --cached **/*.png
Add them again
git add **/*.png
Ready to commit!

Programmatically overwrite a specific local file with remote file on every git pull

I have an XML file that we consider binary in git. This file is externally modified and committed.
I don't care about who edited it and what's new in the file. I just want to have the latest file version at every pull. At this time, at every git pull I have a merge conflict.
I just want that this file is overwritten on every git pull, without manually doing stuff like git fetch/checkout/reset every time I have to sync my repo.
Careful: I want to overwrite just that file, not every file.
Thanks
I thought you could use Git Hooks, but I don't see one running before a pull...
A possible workaround would be to make a script to delete this file and chain with the needed git pull...
This answer shows how to always select the local version for conflicted merges on a specific file. However, midway through the answer, the author describes also how to always use the remote version.
Essentially, you have to use git attributes to specify a specific merge driver for that specific file, with:
echo binaryfile.xml merge=keepTheirs > dir/with/binary/file/.gitattributes
git config merge.keepTheirs.name "always keep their file during merge"
git config merge.keepTheirs.driver "keepTheirs.sh %O %A %B"
git add -A
git commit -m "commit file for git attributes"
and then create keepTheirs.sh in your $PATH:
cp -f "$3" "$2"
exit 0
Please refer to that answer for a detailed explanation.
If the changes to your files are not actual changes, you should not submit them. This will clutter your version history and cause numerous problems.
From your statement I’m not quite sure which is the case, but there are 2 possibilities:
The file in question is a local storage file, the contents of which are not relevant for your actual sourcecode. In this case the file should be part of your .gitignore.
This file is actually part of your source and will thus have relevant changes in the future. By setting up the merge settings like you are planning to do, you will cause trouble once this file actually changes. Because merges will then be destructive.
In this case the solution is a little bit more complicated (apart from getting a fix for the crappy tool that changes stuff it doesn’t actually change …). What you are probably looking for is the assume unchanged functionality of git. You can access it with this command:
git update-index --assume-unchanged <file>
git docu (git help update-index):
You can set "assume unchanged" bit to
paths you have not changed to cause git not to do this check. Note that setting this bit on a path does not mean git will check the
contents of the file to see if it has changed — it makes git to omit any checking and assume it has not changed. When you make changes
to working tree files, you have to explicitly tell git about it by dropping "assume unchanged" bit, either before or after you modify
them.

extract all files changed in a git commit

I need to make a patch for someone (they are not using git) - a zip of the files changed by a commit.
I thought something like
git archive --format=zip commitguid > myfiles.zip
but this extracts the entire thing, not just the changed files. Is there any way to do this?
And to make it more complicated - is there any way of doing this with multiple commits (yes I should have branched before making the changes but that's hindsight)
EDIT
Based on #Amber solution below I can do this in 2 steps in Git Bash for windows with 7Zip installed in c:\data\progs.
git diff --name-only a-sha b-sha > tmp.txt
/C/data/progs/7za.exe a myzip.zip #tmp.txt
git diff --name-only <oldsha> <newsha> | zip dest.zip -#
filling in the proper SHAs/refs. For instance, to create a zip of only the files that changed between the master and feature branches:
git diff --name-only master feature | zip dest.zip -#
See also git help format-patch. It produces a diff patch of all changes in a commit along with commit author, date, message, and some nice diff stats. You could zip and send that.
I found this solution to the question (on github-gist, from user rmkpatchaa).
It doesn't require any external tools and is a one line command in a windows Git Bash window:
git archive --output=changes.zip HEAD $(git diff --name-only SHA1 SHA2 --diff-filter=ACMRTUXB)
It creates a standard zip archive with only the files changed between the two commits, no extra git stuff or anything, and doesn't require any extra tool on the receiving side.

Resources