I am a new programmer on the team. And on my first day, I have this renamed file inside the scene, ready to be executed with git:
$ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: .gitignore new file: reports/SQLS.rar renamed: account/enter_rules.php -> enter_rules.old.php Changes not staged for commit: (use "git add/rm <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) deleted: account/enter_rules.old.php Untracked files: (use "git add <file>..." to include in what will be committed) account/enter_rules.php
For the first two lines, I have no problem. I know what is going on. But for the last renamed:, I'm not sure what to do. The system is working well.
Inside the working directory there are:
account/enter_rules.php
I can not find enter_rules.old.php file.
It seems that another programmer created a copy from the file, named the actual one as .old, did some tests and new code, which made changes and forgot to commit. Then he manually deleted old.php
What should be the best approach to deal with this situation? I would like to set the status to git status before starting to work on it and make my changes.
I found this post, but I'm not sure what I should or could have done in my situation. Renaming files in git
After reading all the suggestions that helped me a lot, this is what I did:
- I just made a copy (only for safe) from
enter_rules.php file - I said โgit (index) that the file name has been changed.
$git commit -m "committing name changes" . At the moment, git does not know that .old has been deleted. - Then I typed
$git rm "account/enter_rules.old.php" to resolve the line: No changes were made to commit:. Similarly, we use $git add . for tell git to track <file> , we should use $git rm <file> for tell git to forget about <file> . - Then I typed
$git status and I got the message GREEN: deleted: account / enter_rules.old.php. . Therefore, I must indicate to the index that the .old file has been deleted. I typed $git commit -m "committing delete changes" - Now git knows that enter_rules.php has been renamed enter_rules.old.php and then enter_rules.old.php has been deleted (deleted).
- Then I solved the last line ( Tracked files :). I just told git that a new file was created and it calls enter_rules.php . I added and did as it should be.
All the suggestions helped me solve the problem, so I will try to be honest and give a check, whose is less.
source share