Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way in GIT, to remove files changed from being committed if it has less than 2 characters changed?

Tags:

git

git-diff

diff

I have been working on a project and edited a bunch of files in a folder. This folder resides on my local and not watched by GIT. I usually copy the entire folder into another computer that is watched by GIT to be pushed to the repo. The problem now is that a bunch of files are being shown as changed due to line endings and spaces being shown up, as it's being copied from windows to a linux box.

I did the following command: git diff --stat to show all the files changed with the # of lines/characters changed.

enter image description here

As you can see many of these files have zero changes done to them. However, they still show up in my git status modified section.

How do I remove or revert these back to normal as I never changed anything with these files?

like image 722
Patoshi パトシ Avatar asked Apr 01 '16 20:04

Patoshi パトシ


People also ask

How do I remove a file from a git commit?

If this is your last commit and you want to completely delete the file from your local and the remote repository, you can: remove the file git rm <file> commit with amend flag: git commit --amend.

How do I remove a file from a staging area in git?

To remove a file from Git, you have to remove it from your tracked files (more accurately, remove it from your staging area) and then commit. The git rm command does that, and also removes the file from your working directory so you don't see it as an untracked file the next time around.

What does git diff do?

Comparing changes with git diff Diffing is a function that takes two input data sets and outputs the changes between them. git diff is a multi-use Git command that when executed runs a diff function on Git data sources. These data sources can be commits, branches, files and more.


2 Answers

Check your configuration on your destination Git repo in which you copy those files.

git config core.autocrlf

Make sure to set it to false: git config core.autocrlf false (see more here).

Then double-check the presence and content of .gitattributes files. They can influence eol as well with core.eol directives.

like image 173
VonC Avatar answered Sep 21 '22 17:09

VonC


I think it is more likely that these files are showing up due to mode changes. Try running git diff on one of them. Do you see something like this?

$ git diff query.viewport.js
diff --git a/query.viewport.js b/query.viewport.js
old mode 100644
new mode 100755

If so, then you might be able to solve this with something like:

$ find modules/hotsite/ -type f -print0 | xargs -0 chmod -x
like image 26
Chris Avatar answered Sep 21 '22 17:09

Chris