Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why after copying git repository to another dir I have modified files?

I have my personal small git repository on my laptop. I have just commited the changes and checked that I have nothing to commit - every staged and modified file has been commited.

After that I have copied all the files from this repo to another location and boom! I have uncommitted changes.

I believe I am missing some fundamental git rules. Can anyone suggest me on that ?

like image 495
Patryk Avatar asked Jul 16 '12 14:07

Patryk


People also ask

What happens when you copy a git repository?

Git clone is used to copy an existing Git repository into a new local directory. The Git clone command will create a new local directory for the repository, copy all the contents of the specified repository, create the remote tracked branches, and checkout an initial branch locally.

How do I remove unchanged files in git?

Remove every file from Git's index. git rm --cached -r .

Can I move my git repository to another folder?

To do this without any headache: Check what's the current branch in the gitrepo1 with git status , let's say branch "development". Change directory to the newrepo, then git clone the project from repository. Switch branch in newrepo to the previous one: git checkout development .

Is it safe to copy .git folder?

You can copy it, everything is inside the . git folder and is not dependant on anything else. just cloned my whole dev-environment with 4 repos in it by simply copying it a few times and making each its own branch. worked flawlessly.


3 Answers

What I did, run

git diff | grep -B 2 @@ | grep +++

to get the actually changed files, then do revert on all others

like image 184
Erik Romson Avatar answered Oct 17 '22 16:10

Erik Romson


Your files on windows probably have carriage-return line-feed line endings and you likely have core.autocrlf true on your windows box. Don't copy it like that between different platforms. Instead create a new git repository on the linux box and pull from the the Windows box. You can either use git bundle or git daemon on the Windows machine to expose the repository. Or you could make a bare repo on the linux box and git push --mirror to it from the Windows machine then clone that where you want the final version to end up.

Or - quite likely you can already just do a git reset --hard HEAD and fix it on the linux box as-is. Possibly you should delete everything except the .git folder first to ensure a completely clean working tree.

like image 42
patthoyts Avatar answered Oct 17 '22 17:10

patthoyts


If you have nothing on stash to lose, do:

git checkout .

This will revert the working tree to your previous commit

like image 31
Bruno Peres Avatar answered Oct 17 '22 16:10

Bruno Peres