Fix line sh endings from mono github? - github

I am trying to build mono on windows, but the .sh files give errors about the carriage returns :
$ ./autogen.sh --host=i686-pc-mingw32 --profile=/usr/opt
./autogen.sh: line 4: $'\r': command not found
./autogen.sh: line 6: $'\r': command not found
./autogen.sh: line 9: $'\r': command not found
The .gitattributes file has this line({cr:
*.sh crlf
I can edit and remove the cr, but then when I try to do a reset so that it will blow away the local file and reget the file from origin, the gitattributes are also blown away:
git fetch origin master
git reset --hard FETCH_HEAD
Looking at the mono repository, they have the .gitattributes like this, but none of the build instructions addresses this issue.
What is the proper way to deal with line endings when building mono on windows? Surely I'm not supposed to manually run dos2unix after everytime I pull?

Make sure that you have
git config --global core.autocrlf false
That will avoid global conversion done (in addition of the .gitattributes directive)
I can edit and remove the cr
Yes, but then you need to add and commit first, before doing the:
git rm --cached -r .
git reset --hard
Otherwise, the .gitattributes would be restored to its previous state.

Related

What actual git command does `Assume Unchanged` in Eclipse Git run in the background?

When doing git status on the command line, git lists modifications:
and then I go to Eclipse and do Assume Unchanged via menu on one of the files listed above:
and then rerunning git status on the command line again, I'm seeing that the file has been (properly) removed from the listed modifications:
I'm wondering what does this Assume Unchanged menu command equates to in terms of Git commands? What about other choices from that menu (Untrack & Replace with HEAD Revision)?
Is it possible to see the Git commands running behinds the scene in Eclipse when executing those menus?
Eclipse does not delegate to the command line but uses JGit which is a pure Java implementation of Git directly accessing the files in the .git folder. You don't need to have the command line Git installed to use Git in Eclipse.
The Assume Unchanged Git command line equivalent is:
git update-index --assume-unchanged
See also:
Git documentation: git update-index
Because Eclipse uses the same terms, the Git command line equivalents are easy to find.

Eclipse eGit on Linux screwing line endings

Because of the changes in line endings, commits looks a lot bigger than they should be.
I have egit 4.6.1.201703071140
Before using egit, the command
git ls-files --eol
shows
i/mixed w/mixed attr/ somefile
then, after commit in Eclipse via git staging view, it is:
i/lf w/mixed attr/ somefile
Another example:
i/crlf w/crlf attr/ somefile2
becomes:
i/lf w/crlf attr/ somefile2
You can see egit is changing the first column to i/lf.
In GitHub you can use ?w=1 to dampen the noise, but how do I fix the problem itself?
git config
core.autocrlf=input
core.repositoryformatversion=0
core.filemode=true
core.logallrefupdates=true
remote.origin.url=https://github.com/plutext/docx4j.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
branch.master.rebase=false
According to https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration:
You can tell Git to convert CRLF to LF on commit but not the other way around by setting core.autocrlf to input.
You probably want to use false instead.

Cocoapods gitignore not working in swift3 xcode project [duplicate]

This question already has answers here:
How do I make Git forget about a file that was tracked, but is now in .gitignore?
(33 answers)
Closed 5 years ago.
I have an already initialized Git repository that I added a .gitignore file to. How can I refresh the file index so the files I want ignored get ignored?
To untrack a single file that has already been added/initialized to your repository, i.e., stop tracking the file but not delete it from your system use: git rm --cached filename
To untrack every file that is now in your .gitignore:
First commit any outstanding code changes, and then, run this command:
git rm -r --cached .
This removes any changed files from the index(staging area), then just run:
git add .
Commit it:
git commit -m ".gitignore is now working"
To undo git rm --cached filename, use git add filename.
Make sure to commit all your important changes before running git add .
Otherwise, you will lose any changes to other files.
Please be careful, when you push this to a repository and pull from somewhere else into a state where those files are still tracked, the files will be DELETED
If you are trying to ignore changes to a file that's already tracked in the repository (e.g. a dev.properties file that you would need to change for your local environment but you would never want to check in these changes) than what you want to do is:
git update-index --assume-unchanged <file>
If you wanna start tracking changes again
git update-index --no-assume-unchanged <file>
See git-update-index(1) Manual Page.
Also have a look at the skip-worktree and no-skip-worktree options for update-index if you need this to persist past a git-reset (via)
Update:
Since people have been asking, here's a convenient (and updated since commented on below) alias for seeing which files are currently "ignored" (--assume-unchanged) in your local workspace
$ git config --global alias.ignored = !git ls-files -v | grep "^[[:lower:]]"
To untrack a file that has already been added/initialized to your repository, ie stop tracking the file but not delete it from your system use: git rm --cached filename
Yes - .gitignore system only ignores files not currently under version control from git.
I.e. if you've already added a file called test.txt using git-add, then adding test.txt to .gitignore will still cause changes to test.txt to be tracked.
You would have to git rm test.txt first and commit that change. Only then will changes to test.txt be ignored.
Remove trailing whitespace in .gitignore
Also, make sure you have no trailing whitespace in your .gitignore. I got to this question because I was searching for an answer, then I had a funny feeling I should open the editor instead of just cat'ing .gitignore. Removed a single extra space from the end and poof it works now :)
i followed these steps
git rm -r --cached .
git add .
git reset HEAD
after that, git delete all files (*.swp in my case) that should be ignoring.
Complex answers everywhere!
Just use the following
git rm -r --cached .
It will remove the files you are trying to ignore from the origin and not from the master on your computer!
After that just commit and push!
If you want to stop tracking file without deleting the file from your local system, which I prefer for ignoring config/database.yml file. Simply try:
git rm --cached config/database.yml
# this will delete your file from git history but not from your local system.
now, add this file to .gitignore file and commit the changes. And from now on, any changes made to config/database.yml will not get tracked by git.
$ echo config/database.yml >> .gitignore
Thanks
To remove just a few specific files from being tracked:
git update-index --assume-unchanged path/to/file
If ever you want to start tracking it again:
git update-index --no-assume-unchanged path/to/file
As dav_i says, in order to keep the file in repo and yet removing it from changes without creating an extra commit you can use:
git update-index --assume-unchanged filename
None of the answers worked for me.
Instead:
Move the file out of the git-controlled directory
Check the removal into git
Move the file back into the git-controlled directory
After moving the file back, git will ignore it.
Works with directories too!
Not knowing quite what the 'answer' command did, I ran it, much to my dismay. It recursively removes every file from your git repo.
Stackoverflow to the rescue... How to revert a "git rm -r ."?
git reset HEAD
Did the trick, since I had uncommitted local files that I didn't want to overwrite.
There is another suggestion maybe for the slow guys like me =) Put the .gitignore file into your repository root not in .git folder. Cheers!
If the files are already in version control you need to remove them manually.
another problem I had was I placed an inline comment.
tmp/* # ignore my tmp folder (this doesn't work)
this works
# ignore my tmp folder
tmp/
Thanks to your answer, I was able to write this little one-liner to improve it. I ran it on my .gitignore and repo, and had no issues, but if anybody sees any glaring problems, please comment. This should git rm -r --cached from .gitignore:
cat $(git rev-parse --show-toplevel)/.gitIgnore | sed "s/\/$//" | grep -v "^#" | xargs -L 1 -I {} find $(git rev-parse --show-toplevel) -name "{}" | xargs -L 1 git rm -r --cached
Note that you'll get a lot of fatal: pathspec '<pathspec>' did not match any files. That's just for the files which haven't been modified.
I have found a weird problem with .gitignore. Everything was in place and seemed correct. The only reason why my .gitignore was "ignored" was, that the line-ending was in Mac-Format (\r). So after saving the file with the correct line-ending (in vi using :set ff=unix) everything worked like a charm!
One other problem not mentioned here is if you've created your .gitignore in Windows notepad it can look like gibberish on other platforms as I found out. The key is to make sure you the encoding is set to ANSI in notepad, (or make the file on linux as I did).
From my answer here: https://stackoverflow.com/a/11451916/406592
If you need to stop tracking a lot of ignored files, you can combine some commands:
git ls-files -i --exclude-standard | xargs -L1 git rm --cached
This would stop tracking the ignored files. If you want to actually remove files from filesystem, do not use the --cached option. You can also specify a folder to limit the search, such as:
git ls-files -i --exclude-standard -- ${FOLDER} | xargs -L1 git rm
On my server linux server (not true on my local dev mac), directories are ignored as long as I don't add an asterisk:
www/archives/*
I don't know why but it made me loose a couple of hours, so I wanted to share...
One thing to also keep in mind if .gitignore does not seem to be ignoring untracked files is that you should not have comments on the same line as the ignores. So this is okay
# ignore all foo.txt, foo.markdown, foo.dat, etc.
foo*
But this will not work:
foo* # ignore all foo.txt, foo.markdown, foo.dat, etc.
.gitignore interprets the latter case as "ignore files named "foo* # ignore all foo.txt, foo.markdown, foo.dat, etc.", which, of course, you don't have.

diff after EGit commit changing whole file, but ok in command line

I don't understand why a commit in EGit is changing the whole file.
Yes, I'm on Windows, and I have core.autocrlf=true set globally in /etc/gitconfig.
Here's what I don't understand:
the working copy starts off with DOS line endings both before and after edit
When I edit the file in Eclipse and look at git diff through the command line, I only see the lines that I changed in the diff.
If I git add and git commit through the command line as well, the git diff HEAD^ shows only the lines I changed.
When I do the commit through Eclipse/EGit instead, git diff HEAD^ shows the entire file as changed, as if the Windows line endings were just added -- when my working copy already had DOS newlines before I touched it.
Any idea why the different behavior in EGit vs. git command line? Where else could Eclipse/EGit be mangling line endings?

How to remove \r when pushing commits to Gerrit from Windows?

I and a colleague of mine work in Eclipse on Windows machines.
When I push my changes to Gerrit, there are \r marks in the source view.
When my colleague does the same, there are no such characters.
The git settings on both machines are equal to:
$ git config --global --get core.eol
native
$ git config --global --get core.autocrlf
false
$ git config --global --get core.whitespace
I'm using following Eclipse settings.
I tried to run File -> Convert line delimiters to -> Windows, but it didn't help (git status didn't show any modified files after I did this).
How can I make sure that when I commit my changes, there are no \r characters in Gerrit?
The \r is because windows line endings are \r\n (vs. unix line endings which are just \n) You could switch to unix line endings but you would have to commit all the files.
Gerrit has an option to hide line endings, it's under preferences when you're in the source view. This seems like the best option.