Thursday, 29 March 2012

Renaming a file in XCode and pull it to the Git repository

When I was working with XCode and Git repository, I have noticed that for renaming task, it could has some problems.

This could be mainly because for the repositories (Git, Svn), the renaming action has been splitted into two steps: remove the original file and create a new file with the new name.

To do it in a secure way, the best is doing it mixing the git terminal command and Xcode user interface.

1. Make a copy of the old file
1.1 Go to the file directory
1.2 Copy the old file with the new name

Now, in the directory you have both files with the same content:
 - One with the old name and
 - One with the new name

2. Remove the old file
2.1 Go to the directory and remove the old file
2.2 Go to the Xcode. You will see that Xcode has noticed something has happened with the old file, because instead of the icon of "m" on the left of the file name, it will be a empty square. Right click on it and select "Delete"
This is necessary because it will modified a config file inside of Xcode, used to compile the project.
2.3 Do a commit with Git to upload the changes in the repository. You will see two files has been changed:
 - The old file
 - The Xcode config file

3. Creates a new file
3.1 Go to the Xcode. On the folder where the new file should be, right click on it and select "New -> File" and creates a new empty file with the new name
3.2 Open the file copied in the step 1 and copy all the contents of it to the new file created with Xcode. You will see on the right side of the new file, there is a "A" symbol. This is because for repository, this file has been recently added and it is not uploaded yet.
3.3 Remove the file created in the step 1.
3.4 Do a commit with Git to upload the changes. This time there will be two file modified also:
 - The new file added
 - The Xcode config file

No comments:

Post a Comment