Git commit without files or folder - git-commit

Git is telling me to commit some 10000 changes but here's the catch, I deleted the folder in which the files to commit are located. Any thoughts on how I can stop git from telling me this.

Run git reset --hard origin/<branch_name> and the branch will realign with your origin counterpart.

If you want your directory or files to do not track by git
Run this command
git update-index --assume-unchanged <directory> or <file>

If those files in the folder are don't need in repo, you may add the folder path into .gitignore file. then git won't ask again to commit changes.

Related

Update git branch after deleting a file from local system

I have deleted a file in my local system. Now I would like to update the locale branch + remote branch. So that the file is removed from the remote branch as well.
I did
git add -u
It deletes the removed file from the local branch but the file still stays in remote branch.
How can I delete the file from remote branch too?
Try removing the cached files:
git rm -r --cached .
git add .
git commit -m "cached problems"
git push
You have to commit your changes (the deletion of 1 file):
git commit -m "One file deletion"
And push it to remote branch:
git push
you need to push your changes to remove using. Ensure you pull the latest code first
git pull
git commit -m "Your message"
git push
Remove a file from local repository should automatically reflect itself on the remote repository once you pushed it.
You first need to commit your changes though:
git commit -m "Removed a file"
And after that push your code with git push
If you want to keep your local file, but remove it from online you'll have to use the
git rm <file-name> --cached
as the answers above stated + you'll need to add it to your .gitignore file so any changes to that file would be ignored.

Git merge conflict with workspace.xml

I'm trying to push my Rails project to Heroku, but Git isn't allowing me to do anything at the moment. Here's what I've done so far:
git push heroku failed because the heroku branch was "ahead" of my local branch, which should not have been possible.
I pulled and there was a conflict with .idea/workspace.xml. I wasn't able to find out what that file is, but it's huge and Git wrote all kinds of garble to it. Too much to manually "resolve" conflicts.
I saw some stackoverflow posts talking about git-ignoring that file (maybe it's some IDE file for RubyMine or something?), so I tried to move the file away to avoid the conflict
I ran git add -A (also tried git add . and git add)
git commit --amend fails because "You are in the middle of a merge"
git merge --abort fails because "Untracked working tree file '.idea/workspace.xml' would be overwritten by merge (despite the fact that the file has been moved)
git reset --merge fails for the same reason.
How can I make Git work again?
.idea/workspace.xml
This file is your idea workspace files. They are generated by IntelliJ tools.
I saw some stackoverflow posts talking about git-ignoring that file (maybe it's some IDE file for RubyMine or something?), so I tried to move the file away to avoid the conflict
Simply add the folder to your .gitignore but since its already committed you will have to remove it from the repository:
# Quit the merge
git merge --abort
# remove the whole folder from the repo
git rm -rf --cached .idea/
# add it to the .gitignore: idea/
# add and commit your changes
git add .- A
git commit -m " Removed idea folder"
git push origin <branch>
If you still unable to do it?
First reset the code to the previous state and then do the above code again.
The reset will take you to your last commit before the pull
git commit -am "message" worked (as opposed to amending a commit)
I have resolved a similar problem by simply deleting the workspace.xml file. By building and running the program again idea will autogenerate a compatible file.

Unstage a file in previous commits in git

We use git together with our iOS app, and we're now planning to make the app's code open source. The problem is we don't want people to have access to our API keys because the API itself shouldn't be accessible by the public.
The API keys are all in APIConstants.h and .m. I'm thinking of unstaging them in future commits, but I understand that people can still check out older commits. Is there any way I can disable the checking out of those two files even from older commits?
The other solution I can think of is deleting the .git folder altogether, add APIConstants to the .gitignore, and doing git init again at the expense of deleting all of our commit history.
Do it like this:
$ git rm --cached APIConstants.h
$ echo APIConstants.h >> .gitignore
$ git add .gitignore
$ git commit -m "Remove and ignore APIConstants.h"
I think you can accomplish this by running the following command:
git rm --cached file
and then adding the file to your .gitignore file so it's not added again later.
adding the file to .gitignore will guarantee that the file won't be included in the future commits.
However, as you said, it is already available and users can still download the old file. You could remove them from the repository altogether..
git rm --cached <file>
Or, if you want to tell the repository to stop tracking a file, you could use..
git update-index --assume-unchanged <file>
and this can be reverted by using,
git update-index --no-assume-unchanged <file>

Cannot push, pull or merge git. "Working copy has uncommited changes"

I have recently set up a git repository on bitbucket, and have added an old project onto it. I have committed and pushed a change as a test, but now I face this problem.
Each time I try to Pull, Push, or Merge I get this error message:
"The working copy 'Project_Name' has uncommitted changes".
And I have committed this change several times:
EDIT: I did 'git status' and got the following:
# On branch master
# Your branch is ahead of 'origin/master' by 2 commits.
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: Crunch.xcodeproj/project.xcworkspace/xcuserdata/Neil.xcuserdatad/UserInterfaceState.xcuserstate
#
no changes added to commit (use "git add" and/or "git commit -a")
Help would be greatly appreciated, SirKaydian
Step 1:
git rm --cached ProjectName.xcodeproj/project.xcworkspace/xcuserdata/username.xcuserdatad/UserInterfaceState.xcuserstate
Step 2:
git commit -m "Removed file that shouldn't be tracked"
Okay, turns out I just had to make a comment
//THIS IS A TEST
And commit that. Now it works fine. This must have just been some strange bug.
Thanks for the help though, SirKaydian
I'm unfamiliar with the .xcuserstate file, but it sounds like a user-specific file. Generally user-specific files have no business in source control. They change frequently, generally are binary and thus difficult to diff, and aren't helpful to other users. Try closing down your IDE then running the commands or try adding this file name to your .gitignore file.
I solved this problem by:
git push <remote> localbranch --force.
Do not use the --force flag unless you’re absolutely sure you know what you’re doing.
git rm --cached *.xcuserstate *.xcuserdata
Run the above command. Then commit, then push.
See here: Xcode says "Uncommitted Changes" Whenever I try to git pull or push
You may need to run them separately :
git rm --cached *.xcuserstate
git rm --cached *.xcuserdata

Trying to add .rvmrc to ignore, its not working

So I modified my .rvmrc to what I need on my server, commit to git and pushed to origin.
Then I added .rvmrc to my .gitignore, but when I do a git status it shows the file has been modified.
I'm trying to fix it so it has my local settings now since the master has the server's version, and I don't want it to pickup the change I made to my local rvm settings since I added it to my .gitignore.
From the Git Documentation at Kernel.org:
A gitignore file specifies intentionally untracked files that git should ignore. Files already tracked by git are not affected.
The solution follows:
To stop tracking a file that is currently tracked, use git rm --cached.
I would do this:
$ git rm --cached .rmvrc
and try again.
Try:
git update-index --assume-unchanged .rvmrc

Resources