Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 4

Overwriting local directory for a repository and then creating a new version from that

Hi,

 

   New to github. I'm using it on windowns. Due to some confusion when I started this job, rather than work directly on the local copy of the project/repository (.net web forms by the way) I cloned the local copy to another directory and worked there. This meant that I was accumulating changes that were not in the local copy  for the repository but in the cloned version. 

 

   While I could do a diff on every file in the solution and move only those that had changed from my cloned copy to the local repository directory, I feel this would be difficult and perhaps dangerous. I would like to overwrite the entire solution with my current cloned version. Then I would like to make that the next version checked into Git. 

 

   The problem I see is that I would not have checked anything out so the status of files would not be correct to be sent back up to the repository.  Also, Git would have no idea what files had changed and which hadn't so they all would have to go into the repository just to be safe. Is there a way to  mark all files as "changed" befpre checking them in?

 

   Someone suggested that it would be easier for me to create a new repository for my cloned version, name it something like "solution2019" and sunset the old respository. Any advice would be appreciated.

 

Thanks,

Neil

3 Replies
Highlighted
Community Manager
Message 2 of 4

Re: Overwriting local directory for a repository and then creating a new version from that

I'm not certain I understand your setup, so my answers may be all wrong if I misunderstood anything. It sounds to me like you're saying that you:

 

  1. Used the `git clone` command to create a local version of a remote repository
  2. Used some other method (like copy all the files from directory A to directory B) to create another copy of the local version of the remote repository
  3. Did all your work in the copy of the local version of the remote repository

 

Now that you've done all of that, you want to:

 

  1. Take the contents of the copy of the local version of the remote repository
  2. Use those contents to update the local version of the remote repository
  3. Then use the updated local version to update the remote repository

 

First, you say you're concerned that you didn't check anything out. You're in luck! With git, you don't ever check out files because it doesn't use the check-out/check-in model that older version control systems used. You change the files, add them to the "index", and then "commit" the changes to the repository. Git figures out the rest, including what files had actually changed and which ones hadn't. The one caveat is that you have to tell git if you want it to start tracking a new file or stop tracking a file you've deleted. This can be done pretty easily in the "add to the index" step.

 

So, assuming that you can make the directory where the local version of the remote repository look exactly like the modified version of your copy of the local version of the remote repository, then you can commit the contents with these two commands:

 

git add --all
git commit

I hope that helps and let me know if you have any other questions.

 

Copilot Lvl 2
Message 3 of 4

Re: Overwriting local directory for a repository and then creating a new version from that

Thank you so much for replying. It's an odd question, I know. In terms of the three things in your list, only the last two are true. I did NOT use the git clone command or any git command, in fact. I simply copied the local directory that holds the project that git uses to another directory and worked there. So the git local directory was left alone and I worked in the copied directory. Git was never part of the equation, unfortunately.

 

I think you are saying that I can copy the entire directory I've been working in and overwrite the git local directory, then use the add and commit commands you list below? The result would be that the next version in git would be whatever is in the directory I would use to overwrite the current git local directory. I will read up on the add command. I'm a bit confused as to how or when git would know if I added or deleted a file so it could decide how to track it. Will the add command as you have it below force git to ask me about new or deleted files or do I have to specify them myself?

 

I will read about it but any pointers would be appreciated. Thanks again. I am used to TFS (source save) and subversion. :-)

Community Manager
Message 4 of 4

Re: Overwriting local directory for a repository and then creating a new version from that


@fig000 wrote:

I think you are saying that I can copy the entire directory I've been working in and overwrite the git local directory, then use the add and commit commands you list below? The result would be that the next version in git would be whatever is in the directory I would use to overwrite the current git local directory.

 

Yes, that's what I'm saying. You'll want to use something that will make the destination directory an exact copy of the source directory, like rsync or robocopy, because if you use a normal copy, any files that you deleted in the source will still exist in the destination. But other than that, it should work just fine.