After checking git diff, how can I ignore changes in a few files that I dont want to add to this commit? - ios

Consider I have made some changes in a few files or classes.
FYI: I am an iOS Developer and use XCODE for development.
Now, After checking git diff from terminal, there are a few changes that I want to ignore and not add to the commit that I am about to make. How can I ignore changes in a few files that I dont want to add to the commit? And also, how to make sure that in future commits, it should not get added.
Thanks in advance...

There are two things you need to know about here:
First, how to ignore certain files permanently, even for future changes. This is typically done for files that are auto generated by your code, such as build files, or local settings (a swap file for vim for example). For this, you need to add the file patterns in a .gitignore file at the root of the repo directory. Read more on it here.
Second, how to ignore certain files for the following commit only. For this you can either hand pick the files you want to add by doing git add <file_name>, then the commit will only have these files, or you could stash your changes to the unwanted files, add all files, commit, then unstash. Read more on stashing here.

If these are files that you will never want to commit, then the answer is to use a .gitignore on your repo with the file patterns you want to ignore.
If you have, in the same file, some changes that you want to commit, and some that you don't, then you can do interactive staging. You start it with git add -i and typing p you select the patch option, git will ask you which file do you want to commit partially, you select the file and then git you show you every hunk of changes you made in the file and you select if you want to stage that hunk or not.
If you can use git-gui or another gui this process can be even simpler.

Related

'.pbxproj' file is missing in commits list

currently building a project clone and push all the changes to my github account step by step.
And i always used to see 'Twitter.xcodeproj/project.pbxproj' checked together with modified .swift files.
However, i don't see it now. I've reopened and did some additional changes to the code, but still nothing.
Is that ok, if it's not pushed?
And how do i get it back to normal if it's not?
The list you are looking at is generated by git status. Well, git status does not include any files that didn't change. So you should not expect to see project.pbxproj in the list unless you did something that would change it (like making a new code file and adding it to your project). Merely editing your existing code wouldn't change it, so it doesn't appear.
(In a way, this is a case of the classic confusion as to what git status means. Beginners often think that it's a list of your files, or a list of the files that will go into this commit. It isn't. A commit always contains all your files. But git doesn't bother to list them in the git status, because that could be an unnecessarily huge list. There are ways to find out what's in the commit, but the screen you are displaying is not how to do it.)
TL;DR Don't worry, be happy.

How to remove a directory that no longer exists but is in the history of mecurial

I'm using the free plan on bitbucket to hold a repo in mecurial. There is one other person using the repo with me. When we first started we were putting everything into the repo. That included a folder called documents that held a ton of pdf files. We have now excluded that folder but all those documents and their history are still in our repo. The free version of bitbucket allows for a repo of 2 gig. I'd like to remove the history of this documents folder from the history because we are closer to the 2 gig limit then i'd like to be. Is there a good way to get rid of that history. What are my options. I'm not finding much online but that could very well be because i'm using the wrong words to search.
I tried to use hg remove Documents* but that didn't work because it's telling me that there are no tracked files.
Update --
I looked in TortoiseHg and on rev 91 i added a ton of files in the Documents folder (it has sub folders as well if that matters). So I think that is likely where the size of the repo blew up. So if anyone knows how to remove those from history i'd be interested.. and is it safe to remove them. We do not need them in the repo.
The normal way to remove history is to create a new repo using hg convert
Before you start you tell everyone to stop using the repo.
then your run hg convert specifying the files you want to exclude.
Once you are done you tell everyone to start using the new repo.

What Discard all changes in Xcode source control actually does?

As in question, I wonder if there is some documentation about what this Xcode command does (Source Control -> Discard all changes) ?
I guess it reverts to last commit but on local branch ? Can somebody confirm that it doesn't affect the same remote branch automatically ?
I didn't use git in XCode, but I can be so sure that Discard all changes will NOT affect history in the remote.
It will most probably discard all unstaged changes you made to the tracked files in the working directory, simply like executing git checkout -- . from the terminal.
With unstaged, it means changes you once executed git add -u for will not be discarded.
By the way, to find out what it actually does, a test by yourself is needed.
I ran into a similar problem in which I wanted to roll back to my most recent local commit, and being unfamiliar with command line git, I took a chance with selecting 'Discard Changes in /filename/' and it did exactly the same thing all the websites said git checkout would do.
Once again, this is just my "test" but the feature works as advertised.

I need to move some files from my existing git repo to a new one. Can I retain their history?

I am creating a new project, but want to add files from an older git repo. I want to add a bunch of files form the old project to the new one but wish to retain the history of those files in addition to putting the new project onto a git repo as well.
What is the right way to do it? I have searched for ways to move files, but then, I need a new git repo with the history from older files, how can I accomplish that?
try the method posted here. It should fit your problem.
http://saintgimp.org/2013/01/22/merging-two-git-repositories-into-one-repository-without-losing-file-history/
In this case the author is moving all files to a new subdirectory. In your case you should only move the files to the subdirectory you want. After that you can handle your old files and the new project as separate subdirectories.
Best Regards
You can try the suggestions mentioned in the post.
Moving Files from one Git repository to another preserving the history
Git: Copy a file or directory from another repository preserving the history

GIT: How do I checkout all files from working directory?

I want to discard all files to which changes have been made.
While working with Xcode, I accidentally open .xib files. If the version of Xcode in which the files were generated is different than my version, it automatically marks these files as Modified (M) and it shows up in my git as well. I need to manually remove all of the file. I'm sure there must be a better way to do it.
git reset --hard
will reset to the committed state,
git checkout -- .
will check out the staged state
Select the .xib files in question, right click/control-click on your selection, and select the "Discard changes in selected files" option. This will revert the files back to their stored versions (it's the equivalent of the git checkout command in that it removes the file from the list of changed files)
For safety, I tend to view the xib files in Version mode to ensure that only the Xcode version boilerplate is changing before I do this.

Resources