How to detach a folder from being tracked without deleting any files from it? - linux

I completed MyProject1 and have uploaded it in git in fine way with commits after adding each new features. And now I'm starting MyProject2 and was trying to add the URL for the remote repository. But then I found out that I had mistakenly added the URL in Documents instead of MyProject1 folder because of which MyProject2 folder is also being tracked in MyProject1. And I'm not being able to add URL to MyProject2 but instead facing merge issues.
Is there any way to detach the track from my Document folder without deleting any of my files from Documents.
Structure is this way(I'm using Linux):
Documents
(And inside Documents there is:)
MyProject1
MyProject2
And other folders which are also being tracked.

We can manually do it with below steps
create a file .gitignore in base directory.
If MyProject1 and MyProject2 are already part of git tracking, Please run commands
git rm -r --cached MyProject1/
git rm -r --cached MyProject2/
Open the file in text editor and add below lines in file
MyProject1/
MyProject2/

Best way:
Create a .gitignore file following #Vinayagam R
Ignore file locally
Those methods won't affect other contributors working on the same remote repository:
Use update-index:
If you want to stop tracking a file at certian point.
git update-index --assume-unchanged yourDirectoryName
--assume-unchanged is the flag which means the files should not change locally. In other words, it is used when ignore files that you do not need to change locally (or should not change).
To revert it use update-index --no-assume-unchanged yourDirectoryName
Using .exclude
In your working directory edit .git/info/exclude

Related

Git thinks a file within a symlinked directory has been deleted after recreating the symlink, how can I fix it?

I have a symlinked directory within my repository, which links to files elsewhere on the filesystem. For whatever reason, the symlink breaks every now and then, and it turns into a regular empty folder. So I deleted the empty folder, and recreated the symlink with ln -s ../../ ext, which appears to have worked as I can browse that folder and see the contents. But when I run git status, it appears all the files that should be visible within the ext folder are missing. How can I make git see that they are there again, within the symlinked directory?
This is on Ubuntu 18 by the way.
Your setup is odd, because Git does not follow symlinks, it just stores them.
That is, if you have a symbolic link ext -> ../.. and you run git add ext, Git creates, in the index, an entry with mode 120000 (symlink) to store the blob contents ../... Committing will create a commit that, when extracted, will create the symbolic link ext pointing to ../... Git will not store any files within ext when it is storing this symbolic link.
If, on the other hand, you have an existing commit that contains files named ext/foo and ext/bar, and you clone this repository at this commit, or extract this commit into a new and otherwise empty work-tree, Git will see that in order to write to files named ext/foo and ext/bar, your OS requires that ext exists as a directory. It will therefore create the empty directory ext, in which it will then create files foo and bar as your OS requires, so as to create files that to Git are merely named ext/foo and ext/bar. These two names, ext/foo and ext/bar, will now be in the index, so that the next commit you make will also contain these two files.
It sounds like you:
cloned a repository (perhaps with git clone --no-checkout?);
manually created a symbolic link in the work-tree named ext, pointing to some existing directory (perhaps one with some files inside it);
convinced git checkout to create ext/foo and ext/bar without first removing the symbolic link ext and replacing it with a directory ext.
This is not a supported mode of operation1 and you should not be surprised when it goes wrong.
1It leads to security issues: Git is meant not to write any files "outside" the work-tree area, and writing to files "under" a symbolic link to a directory outside the work-tree would allow this to occur. Rather than carefully limit symbolic link usage, Git just generally doesn't store files "beyond" any link in the first place—though it's probably possible, through careful manipulation of the index and, at the OS level, the file system in which your work-tree resides, to trick Git manually.
just dont put a repo in a repo, its not worth it

Gitkraken revert deleted files

Currently, I am using GitKraken to upload my files to Gitlab. However, there was a submodule that contained all my files for the project - in an attempt to combine the submodule into the main respiratory, I tried deleting it; however, my entire submodule is gone now. When I go into the trash folder of my Mac, I can see the folder except it is named with extra letters and contains files such as Build and Test Index. Is there anyway to get this submodule back?
UPDATE: I tried reverting the files from the trash folder, but it only put the files back into the derived data folder. Not sure how to get the submodule back, it is asking to initialize it by specifying a URL.

GIT push creates a temporary (?) "file.html~" file of my commited file? Why?

it's my first using the git commands on a linux environment and I got a weird problem. I cloned a git repository and changed the file "index.html" for testing purposes. I use the following commands after that:
$git add .
$git commit - m "test"
$git push
It works fine, expect that it created a second file of the index.html, named "index.html~"why?
thank you :)
/edit: The file doesnt exist in my local repository tho..
Files with ~ are generally created you start editing the file, so I suppose you committed when your index.html was being opened/edited
linux user? use gedit or etc editor?
create .gitignore file and add string inside this file:
*~
git push does not touch your working directory, it just sends your local commits to a remote server. It is essentially a read-only operation on the local repository (just the remote-tracking refs are updated).
So git push can't be the one creating this *~ file. As said elsewhere, your text editor (e.g. Emacs) probably is.
I suggest that you ignore all *~ files by adding *~ to ~/.config/git/ignore (create the file and directories if they do not exist).

Add previously ignored directory to Git repository

My .gitignore file looks like:
html/
cache/
resources/
# Temp files often created by editors
*.~
I know wish to start tracking a specific directory in html, so I add `!html/support/
html/
cache/
resources/
# Temp files often created by editors
*.~
# Track support
!html/support/
After doing so, however, Git still doesn't seem to track html/support/ and all its children.
How do I add a previously ignored directory to Git repository?
Not ignoring doesn't mean tracking.
Just use
git add html/support/
at the root of your git repository.
If the file is still ignored, though, you can use git add -f to force adding it (this will not modify the .gitignore file, just allow one little exception) :
git add -f html/support/
Your .gitignore should add this line:
!html/support/**
You can simply go to the Directory of the File where .gitignore file is located. This File contains all the files that are ignored. You can simply remove the file listing and save it. Then Refresh your project. Then you will be able to commit those files.

How to conveniently sync a file between two git repositories

I have two git local repositories. Both share an identical file, under a different path and under a different name. Currently, when I make changes I have to copy the file from one directory to another.
Is there an alternative way to keep them in sync without manually overwriting the file? I don't want to create a separate repository for this file. I thought one of the following things would work, but apparently, they don't:
git submodule
git subtree
symlink soft
symlink hard
What else is there?
The only other alternative would be a post-commit hook on repoA, which would, on each commit:
check if the file is part of said commit
copy it in repoB with the right path.

Resources