0

I started to code with a previous written code from someone else, but I didn't initiate any git repository at the moment. I still have access to the files made by this other person. I would like to use git to help to compare the initial code and the changes I've made so far. Any idea of how is the best way to do that? Is it necessary to create a git rep or is there a simpler way?

A more general question should be: How to initiate a git repository on an existing folder which has similar code to origin (supposing I initiate a rep with the unchanged code) and then commit your changes merging the similar code as it was part of the remote without losing the changes you made?

Would creating another branch and making a PR to the main with the unchanged code be the best choice?

Andre GolFe
  • 300
  • 5
  • 12
  • Note that you can run `git diff` without a repository (or outside a repository), as a variant of the standard Unix `diff`. It's generally limited to those things that a standard Unix diff can do in this situation, since it has only the same inputs *as* a standard Unix diff, but it's operated the way `git diff` usually is, with the same flags (e.g., `--name-only`). – torek May 29 '21 at 01:13

1 Answers1

2

You should do this:

mkdir repo
cd repo
git init
cp -rv {{someone_else_code_folder}} .
git add --all
git commit -m "Someone else code added."
cp -rv {{my_code_folder}} .
git status
git diff

Antonio Petricca
  • 8,891
  • 5
  • 36
  • 74