Track file but ignore changes, as repo config - linux

It is possible to track one file, but discard changes to it:
git update-index --assume-unchanged <file>
But this is local setting.
How can I make this visible to my team members, without forcing them to locally do the git update-index --assume-unchanged dance?

The answer is that you can't. Git doesn't support doing this and using git update-index --assume-unchanged for this purpose is not a supported use of that feature.
If you have a config file or other file that needs to change depending on the user or system, then check in a template and generate it as part of a local build step. For example, GitHub uses templating and a set of scripts to set up local configuration in a project-independent way.

Related

How to go back to the Working Directory that was not committed

I forgot to commit on the directory where I was working and then I checkout to the previous commit and now I want to back to the directory where I used to work. What can i do ?
If your checkout of the previous version somehow deleted your folder, which was not added/committed, then you would need to rely on a file recovery utility, as detailed in "Can I restore deleted files (undo a git clean -fdx)?", or on your IDE. Some of them keep a local history (IntelliJ IDEA, VSCode through an extension, ...): you might get back some of your files content that way.
In the end, it depends on the exact git checkout command you did, considering this command can update files and/or branches.
That is why it is recommanded to use git switch (branch only) or git restore (files only), instead of git checkout.

How to use vim-fugitive with a git bare repository?

Environment
Setup
I use a git bare repository to version my config files. I can use same commands as if I were using a normal git repository just have to include some flags:
git --git-dir=/home/kunzaatko/.cfg/ --work-tree=/home/kunzaatko/ __command__
instead of
git __command__
Usage
I make use of vim-fugitive with normal git repositories mainly for making a big change and adding it in many different commits by staging partially (only a discrete set of hunks/changes) and committing them separately . I use :Gdiff for this for the nice and productive interface I can make use of.
Desire
I want to do this with my config git bare repository.
What I tried:
Renaming the repository to .cfg.git. This didn't make any change. issue that suggests this should work
I tried to change the b:git_dir internal variable of git-fugitive:
:let b:git_dir=/home/kunzaatko/.cfg/
Changing the working directory to the git directory for fugitive to recognize that it is a git repo:
:chdir /home/kunzaatko/.cfg/
What would be worthy of trying if I knew how:
I think that there may be a way to use the git submodule command to put the bare repo into scope. The problem with that is where to put the root of the git repository... issue that I base this possibility of of
Question
Is there a way to use a git bare repository with git-fugitive?
(or any other suggestion that would solve my use-case)
I agree with #okket, but there is a problem when I use that method.
When in Gstatus window, I cannot get the status of changed files. And I find the reason is that fugitive gets the core.worktree attribute from the GIT_DIR repository.
So for me, the viable way to do this is as follows:
Same as #okket says, set GIT_DIR env variable when using vim/nvim command (GIT_WORK_TREE may be omitted):
GIT_DIR=$HOME/.cfg GIT_WORK_TREE=$HOME [n]vim
For users of fish shell (like me), should use env command:
env GIT_DIR=$HOME/.cfg GIT_WORK_TREE=$HOME [n]vim
Set core.worktree for your git repository:
git --git-dir=$HOME/.cfg --work-tree=$HOME config --local core.worktree $HOME
You can make sure you get it right with the following command:
git --git-dir=$HOME/.cfg --work-tree=$HOME config --local core.worktree
The output should be your HOME path.
If you get the git repository by git clone --bare ..., you need to unset core.bare to avoid git status error warning: core.bare and core.worktree do not make sense:
git --git-dir=$HOME/.cfg --work-tree=$HOME config --unset core.bare
And there is one more thing to notice for this method. You cannot use fugitive outside of $HOME directory where you will get fugitive: working directory does not belong to a Git repository error.
PS: I'd like to comment on #okket 's answer, but due to low reputation I can only post a new answer here.
The environment variables $GIT_DIR and $GIT_WORK_TREE let you point git and fugitive to the dotfile directory when using a bare repository. This solution works with the caveat, that fugitive/git will ignore other repositories while these variables are set.
To limit this environment pollution start vim like this:
GIT_DIR=$HOME/.cfg GIT_WORK_TREE=$HOME vim [file(s)]
In case the syntax is unfamiliar: it is possible to prepend setting environment variables before calling a binary in most (all?) shells. This limits redirecting git through the environment variables to this specific vim instance.
A quality of life improvement would be to put this line into a shell alias or use a full featured dotfile manager like yadm, which is a wrapper around a git bare repository.

how to sync a "shadow" git repository with a main repository "secretly"

I have a client that I do work for via a git repository. I do not want for him to know that I am partly using another developer. I have therefore created a "shadow" repository, that my developer is using.
How to sync the "shadow" repository with the main repository so that the main repository does not know that this is happening?
I cannot merge with a git command, since this will reveal what I really have done.
I could copy and paste all files, but that would visible in git that I have deleted all files and replaced with new files with the same name. That does not look good.
My client is using bitbucket. I could give the other developer my bitbucket login, but I would want to avoid to do that.
What actually work, is that I can open a file in the main repository, delete the content and then paste in the updated code. Then I could commit and it would look is if I had done the work directly in the main repository. But this is time-consuming (and time is something I do not have too much of).
Is there a different way that I could "secretly" copy the content of files from the shadow repository to the main repository? Is there a linux/osx-command I could use that replaces the content of a file without deleting and recreating the file (which I then could use recursively)? Is there a git-command that make this possible without leaving a trail of evidence of what I have actually done?
you can have the same set of local files revisioned by different git repositories, using the command line. Just use the GIT_DIR environment variable. The Git repositories are completely independent, and can track files from the same directory.
rem set Git to use the sub-developer's git repository
set GIT_DIR=/path/to/sub/repository.com
rem verify which repository that you are on
git rev-parse --git-dir
rem pull the sub-developer's latest
git pull
rem merge, commit, change, push, change branches, whatever
rem ... when the code is the way you want it
rem switch to client repository
set GIT_DIR=/path/to/client/repository.com
rem bring main repository up to date
git commit -m"changes brought over from sub-developer"
rem push the updated code to the client repository
git push
this is useful for other development practices, like versioning lab data, local developmental utilities, work logs, and other 'misc' files that seem to accumulate with the source code, but shouldn't be archived with it.
After my error on the first answer, I feel compelled to try again.
try reading in the sub developer branch and comparing/merging to main with git differencing. see 'git help config' for 'diff.external'. I use diffuse.exe and a batch file to map the parameters.
The work flow would look something like this.
rem make a remote to the sub
git remote add MYSUB https://path/to/sub/repository.com
rem see what branches are there
git remote show MYSUB
rem get the branch from the subdeveloper
git fetch MYSUB CurBranch:CurBranch
rem view/manually merge just the modified files
git diff --diff-filter=M MYSUB/CurBranch
rem cleanup
git branch -D MYSUB/CurBranch
git rm MYSUB
rem push to main site
git push
This is the method I use to transfer branches to my lab machine, via a USB memory stick. I have not tried it with a remote connection.

Can I let git warn me when I try to add a file with a file name which is invalid on Windows?

I am developing on a Linux machine. It happened once that I added a file 'sin(x):2.tex' or something similar. This caused some trouble for a friend who uses a Windows system and wanted to clone my repository.
I know there are much more invalid file names on Windows than on Linux. Is there a possibility to make git warn me if I try to add such an invalid file name to my repository?
You can see a good example of pre-commit hook in this gist, in reference to this answer about valid Windows names
# A hook script to check that the to-be-commited files are valid
# filenames on a windows platform.
# Sources:
# - https://stackoverflow.com/a/62888
# - http://msdn.microsoft.com/en-us/library/aa365247.aspx
#
# To enable this hook, rename this file to "pre-commit", move it to ".git/hook" and make it executable
It uses git diff:
git diff --cached --name-only --diff-filter=A -z $against
Note that a pre-commit hook is a client-side hook, meaning it has to be deployed in all repos for all users.
And it can be bypassed (with git commit --no-verify).
Another approach is to set a pre-receive hook (server-side hook) which will block any push including invalid filenames.

Subversion: File properties

I am using Subversion to manage my python code. But I have no idea how to put the file properties of my configuration file.
For example I have the configuration file checked in on my development platform. I want to make sure that
After the configuration file is being checked out. The SVN up process should ignore the modified configuration file.
On the server side I have the golden configuration file. Therefore the SVN commit should ignore the configuration file as well.
I have no idea how to set the properties of the configuration file so I am seeking help here.
Thanks in advance
This comes up enough that it's in the Subversion FAQ
Short version: Create (and version) a "template" configuration file. Users check out a WC, make a filesystem local (not svn) copy which is to be ignored by Subversion, and then modify that copy.
You might want to look at my pre-commit hook.
But first, uou need to remove that configuration file from your Subversion repository. Instead, add a configuration template that developers can copy and use.
Once you remove the configuration file from your repository, you want to set svn:ignore to ignore it. This way, it doesn't accidentally get added if a user does a svn add * or sees it when they do a svn status.
However, if you want to be absolutely certain that this configuration file is never added to the project, you need a pre-commit hook that will refuse a commit if a user does add it.
Why don't you tell SVN to ignore the file?
$ cd path/to/config/file
$ svn delete --keep-local config.file
$ svn propset svn:ignore config.file
$ svn commit
What this does is first tell SVN that it should stop tracking the file (svn delete), then we set the svn:ignorepoperty on the directory in which the file resides, and then we commit these changes.
If you still want the configuration file to be tracked by SVN, then you can either commit your changes excluding the modifications on the file, or external the file in and be sure to ignore externals when committing.

Resources