Moved local git folder and now its asking to stage most of my project files? - linux

I reinstalled my OS (KDE neon) and I thought why not backup my project git folder, before I reinstalled I made sure I commited any code and everything in my git project folder was up-to-date.
So after reinstalling, I moved my project back onto my PC from my backup drive and ran git-status and it wants to stage nearly all of my project?
What do I do? I don't want to commit all these files again when I have not editing any of them? Its nearly 800 files it wants to stage?

You could reset your project using:
git reset --hard branch_name
This would lose any unstaged files.
Or you could stash the changes:
git stash save 'msg'
This works like the previous one, but instead it saves the unstaged files in a separate "memory" (in case you need them later on).
Now, I may assume that the reason you got that situation in the first place is maybe when you restored your data back from the drive, the OS changed some properties on those files, stuff like creation/modification dates, permissions...etc. While the content of the files has not changed but the properties are. Still, git sees them as modified files.

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.

Tortoise SVN undo checkout in repository

I am very new to Tortoise SVN so I hope I use the correct terminology...
I have a repository, say C:/RCode and I was checking it out into say C:/Working. I do not know what exactly went wrong, but I must have checked out something in my repository C:/RCode. As a result, this folder has now features of both a repository and a checked out folder - e.g. it now also has the green v icon overlay next to the icon overlay of a repository.
How can I tell Tortoise that this is should not be a checkout folder?
To make Tortoise SVN forget a folder is a checked out folder, it suffices to show hidden files and folders in the folder of interest and then delete the hidden folder .svn
The command you're looking for is an svn export. An svn checkout is the process of tracking local changes into a series of deltas (inside that .svn folder) so that you may commit changes back to the repository.
An export does essentially what a checkout does, but without the version control aspect of it. The command you would run for your example would be:
svn export file:///C:/RCode C:/Working
Or if you're using TortoiseSVN:
Right click anywhere in Windows Explorer
Enter the URL of the repository and output directory
Specify a revision (HEAD by default)
Select OK.
Simply deleting the .svn folder works as well, but it's an extra step (along with cleaning your Recycle Bin). It's also worth noting that svn export is useful for making a copy of your local working copy (a checkout) to a non-versioned copy somewhere else on your local machine.
svn export C:/Working C:/NonCheckout

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.

Handling line endings for git

Here is what I messed up so far,
I copied (not cloned) a rails project from windows to linux pc
Then created a new branch and made lots of changes
At last commited twice whole project and pushed it to a remote repository with windows line endings.
Problem: so my problem is that, since I copied the project from windows to linux, when I run git status whole project shows modified. I don't see the changes I made specifically. Since I committed and pushed whole project, I lost history of files change.
What is needed: So I want to remove my last two commit but I want to keep my changes that I made. Then I want to convert the line endings from windows to unix of whole project so that when I run git status I see only the files that I changed, not whole project. And then I want to commit and push to remote.
It would be nice if there is a solution for this mess.
I am not sure if this will be helpful, I am working on a rails project and my IDE is rubymine.
To undo your last two commits run this:
git reset --soft HEAD~2. This will put the files involved in the commits into your working directory.
Run git status and they will show as staged changes (ready for commit).
Edit your files.
Stage and commit your changes. Important: Don't push
Run git pull.
Run git push
Make sure you commit your changes and do a git pull prior to git push, otherwise your attempt to push will cause conflict and will be rejected.
You can use git filter-branch.
Similar question here.

Git checkout untracked issue

I'm collaborating with a few other people on a Drupal website which we are version controlling Git. We setup a local Git repository containing our commits.
After a colleague pushed some updates and I fetched and merged into my local dev branch, I began experiencing the following problems:
user#server:/var/www/Intranet/sites/intranet/modules/custom$ git checkout dev
error: The following untracked working tree files would be overwritten by checkout:
themes/bigcompany/panels/layouts/radix_bryant_flipped/radix-bryant-flipped.png
themes/bigcompany/panels/layouts/radix_bryant_flipped/radix-bryant-flipped.tpl.php
themes/bigcompany/panels/layouts/radix_bryant_flipped/radix_bryant_flipped.inc
Please move or remove them before you can switch branches.
Aborting
The issue above typically shows up when I try to checkout into other branches which fails and I am effectively trapped in my current branch.
Referring to this question, there is a suggestion my issue is related to the gitignore file. However, my .gitignore file has nothing indicating any part of my themes directory should be ignored as the following shows:
# .gitignore for a standard Drupal 7 build based in the sites subdirectory.
# Drupal
files
settings.php
settings.*.php
# Sass.
.sass-cache
# Composer
vendor/
# Migrate sourec files
modules/custom/haringeygovuk_migrate/source_data
As mentioned above, my attempts to execute git checkout into any branch fails with the message above. I decided to force it with the -f switch and successfully switched into my target branch but I lost a couple of hundred lines of code - which I'd love to avoid going forward.
I work on a Linux-Ubuntu VirtualBox which my colleagues prefer working in a WAMP setup and use the Git Bash terminal emulator for executing the Git commands. Could the difference in environments be causing these serious issues?
How can I resolve this issue?
Well, the situation is rather simple. You, in your current branch, don't have certain files under the control of Git, but at the same time, you have those files in your working tree. The branch you're trying to switch to, has those files, so git would need to override files in the working tree to perform checkout.
To prevent possible data loss, Git stops the process of switching the branches and notifies you that you should either add those files under the control of Git in a separate commit in your current branch, and only then perform the switch, or simply remove those files from the git way.
Likely you have chosen the second way. Generally you should "force" any operation only if you really understand what you're doing.

Resources