Had a file name
userName.js
imported it using uppercase file name..worked ok on Mac but caused error on Heroku.
import {name} from 'UserName.js'
So I renamed file.. and push it up to Heroku..
mv userName.js UserName.js
git add . && git commit -m 'change file name' && git push heroku master
Same error is occuring..
so I run bash on Heroku..
heroku run bash
ls
for some reason it is still on Heroku as...
userName.js?
I can run
mv userName.js UserName.js as heroku bash..
but next time I push the same userName.js? is back.
Answering my own question.
Saved the contents of userName.js to clipboard.
Removed the old file from git history..
git rm --cached userName.js
touch UserName.js and pasted in old contents..
after pushing up to Heroku..seems to get it right.
Related
I'd like to write a script that, when run, pushes all the last updated files into the matching GitHub repositories.
Here's what I tried:
myPath=absolute_project_path
for i in $*
do
if [[ -d $myPath/$i ]]
then
cd $myPath/$i
git add ./*
git commit -m "update"
git remote set-url origin https://usr:pwd#github.com/username/$i.git
git push -f -u origin main
fi
done
But this is adding all the folders to all the directories: so myrepo1 in GitHub, gets myrepo1+myrepo2 files, and myrepo2 gets myrepo1+myrepo2.
Does anybody know the reason why?
Notes on the workarounds tested, if needed: It seems that the staging needs to be emptied every time before changing file for another repository.
But i tried this also:
- Did a backup of my folders, then ran git rm -f, git add, git commit, git push (caused local folder to get deleted), re-copied from backup, and re-ran the script, but didn't help
- Also tried to manually remove all the folders on GitHub and re-push them, but caused Git to want me to do a Pull. But once the Pull has been done (which caused the deletion of my local files), a re-copy from backup and a new Push caused Git to ask to make a new Pull again... reason why of the push -f
It is only a suggestion, but for this you can use already existing tools like myrepo.
Simply register your repos:
mr register ~/gitHub/repo_1
mr register ~/gitHub/repo_2
...
then if you want to push all your repos, simply type:
mr push
if you wan to pull them all, type
mr update
an so on... read to doc.
I'd like to get rid of some old tags. But I don't want to delete them, I just want to archive them so that I can restore them if necessary.
I am refering to the answer of a smiliar question: How can I archive old git tags?
I have created a new folder ref/archive/tags and moved all affected tags to this folder.
Suppose I can't make the changes directly in Origin, but have to do it in my local repository. How can I push the changes then?
I'm using the following command:
git push origin refs/tags/:refs/tags/
refs/archive/tags/:refs/archive/tags/
And receive the following feedback:
Everything up-to-date
My colleagues can fetch the archive folder, but the old tags remain under refs/tags. What am I doing wrong?
Tags will not be deleted from your coworker's repo unless he deletes them. Just like you can't change a tag without deleting it first. The other option is to clone your repo to a new directory.
To delete all local tags:
for x in `git tag`; do
git tag -d $x
done
git remote update
At the end I used the following script. It archives all tags which are not named "test". Then all tags in the directory "refs/archive/tags" are deleted directly on the origin. Push the archive directory, delete all local tags and fetch the tags from origin. Maybe there are simpler solutions, but this one worked for me like this.
mkdir refs/archive/tags
shopt -s extglob
mv refs/tags/!(test) refs/archive/tags/
ls refs/archive/tags/ | xargs -n 1 -I% git push origin :refs/tags/%
git push origin refs/archive/tags/*:refs/archive/tags/*
git tag -l | xargs git tag -d
git fetch origin +refs/tags/*:refs/tags/*
My colleagues have to use the following script:
git tag -l | xargs git tag -d
git fetch origin +refs/archive/*:refs/archive/* +refs/tags/*:refs/tags/*
Restore all tags if neccessary:
mv refs/archive/tags/* refs/tags/
git push origin --tags
Error
I got error
error: The following untracked working tree files would be overwritten by checkout:
MyProject/xcuserdata/shingo.nakanishi.xcuserdatad/UserInterfaceState.xcuserstate
Please move or remove them before you can switch branches.
Aborting
I try this
(The following untracked working tree files would be overwritten by checkout)
git rm --cached MyProject/xcuserdata/shingo.nakanishi.xcuserdatad/UserInterfaceState.xcuserstate
and
git clean -d -fx ""
git commit -a
git push
When 「UserInterfaceState.xcuserstate」file is not exist, this is work
But Xcode soon make UserInterfaceState.xcuserstate.
When I use Xcode, Xcode make UserInterfaceState.xcuserstate file.
So, Each checkout branch , I must do git clean -d -fx "" each Time.
My ~/.gitignore
this is my ~/.gitignore
.DS_Store
*UserInterfaceState.xcuserstate
*Breakpoints.xcbkptlist
How to ignore the file?
the first error means it is already in your repository (committed). you need to first remove it from the repository, then ignore it.
please read Git ignore file for Xcode projects
https://gist.github.com/3786883
Please search the SO before post questions.
For the change you have made. use git checkout -- <fileName> to discard changes.
Git doesn't ignore the files you already tracked. So just remove that file from git first
git rm -rf file
git commit -m "remove"
git push origin #{branchname}
and after, you're .gitignore will ignore it :)
I've deleted some files from my project, but they still show in the commit screen with a D symbol next to them.
When I try to commit I get the error .... no such file or directory, how can I remove these files aka get rid of the warning ?
The D means deleted. Git still knows about a file if you delete a file with rm or via the finder. To remove a file from git and from disk:
git rm <filename>
git commit -m "message"
In git when you add changes to the staging area (prior to committing) changes that removed a file are not staged by default. Using --all, -A, or --no-ignore-removal options with your git add <filename> will stage all types of changes.
ie. git add . --all will stage all changes before you commit, including deleted file changes.
Alternatively, as mentioned by Dau in his answer if you use git rm <filename> and git remove the file from the working tree and from the index.
According to the comments, it seems that git isn't aware of the file, ie: the file isn't staged in the index. Try running this serie of commands :
git add <filename> // stage the file
git rm --cached <filename>
Maybe you simply deleted the file using some kind of rm <filename>, in that case try to check out the file first, and then try the removal.
git checkout HEAD -- <filename>
git rm <filename>
While I found similar question I didn't find an answer to my problem
When I try to rename the directory from FOO to foo via git mv FOO foo I get
fatal: renaming 'FOO' failed: Invalid argument
OK. So I try git mv FOO foo2 && git mv foo2 foo
But when I try to commit via git commit . I get
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# foo
nothing added to commit but untracked files present (use "git add" to track)
When I add the directory via git add foo nothing changes and git commit . gives me the same message again.
What am I doing wrong? I thought I'm using a case-sensitive system (OSX) why can't I simply rename the directory?
You are in a case insensitive environment. Further, adding without the -A will not take care of the remove side of the mv as Git understands it. Warning! Ensure that no other changes or untracked files are around when you do this or they will get committed as part of this change! git stash -u first, do this and then git stash pop after. Continuing: To get around this, do the following:
mv foo foo2
git add -A
git commit -m "renaming"
mv foo2 FOO
git add -A
git commit --amend -m "renamed foo to FOO"
That's the drawn out way of changing the working directory, committing and then collapsing the 2 commits. You can just move the file in the index, but to someone that is new to git, it may not be explicit enough as to what is happening. The shorter version is
git mv foo foo2
git mv foo2 FOO
git commit -m "changed case of dir"
As suggested in one of the comments, you can also do an interactive rebase (git rebase -i HEAD~5 if the wrong case was introduced 5 commits ago) to fix the case there and not have the wrong case appear anywhere in the history at all. You have to be careful if you do this as the commit hashes from then on will be different and others will have to rebase or re-merge their work with that recent past of the branch.
This is related to correcting the name of a file: Is git not case sensitive?
You want to set the option core.ignorecase to false, which will make Git pay attention to case on file systems that don't natively support it. To enable in your repo:
$ git config core.ignorecase false
Then you can rename the file with git mv and it'll work as expected.
I was able to resolve this, using git 1.7.7 by using a temporary filename:
$ git mv improper_Case improve_case2
$ git mv improve_case2 improve_case
$ git commit -m "<your message>"
(git mv-free variant.)
I ran into this problem in Git on Mac OS X 10.9. I solved it as follows:
git rm -r --cached /path/to/directory
That stages the directory for deletion in Git but does not actually remove any physical files (--cached). This also makes the directory, now with the proper case, show up in untracked files.
So you can do this:
mv /path/to/directory /path/to/DIRECTORY
git add -A /path/to/DIRECTORY
Git will then recognize that you have renamed the files, and when you do git status you should see a number of renamed: lines. Inspect them and ensure they look correct, and if so, you can commit the changes normally.
This is a quick and bug-safe solution:
git mv -f path/to/foo/* path/to/FOO/
Warning! Always rename all files in the renamed folder (use /*).
Do not rename single files. This leads to a bug, described in this answer.
If you first want to see the outcome first, use -n:
git mv -f -n path/to/foo/* path/to/FOO/
After you've made an mv:
Commit changes
Checkout to any other revision
Checkout back.
Now Git should have renamed the folder BOTH in its internal files and in file system.
Force it with -f option:
git mv -f FOO foo
I had one related issue.
One folder named 'Pro' (created first) and another 'pro' (created by mistake). In Mac, it is the same thing, but different according to git.
$ git config core.ignorecase false
the git config rename the files to the right folder(thanks), and also created ghost files in 'pro' (No!!). I could not add ghost file changes to the track and I could not checkout other branches unless carry those those files with me, and i also could not reset it somehow.
Instead of that, i did
$ git rm -r --cached pro
$ git status // => pro files removed, new Pro files untracked
$ git add Pro
To make it extra safe, i did it in a separated fix branch, and then i merged back to main branch
For the ghost file issue created by , can any guru explain How and Why?
Thanks in advance.
This worked great for me on Windows. Used powershell with the following:
mv .\Folder-With-Wrong-Casing .\temp
git add -A
git commit -m "renamed folder with wrong casing to temp"
mv .\temp .\Folder-with-Correct-Casing
git add -A
git commit --amend -m "Renamed to proper casing"
(optional) git push
Thanks to Adam's answer above.
You're not using a case-sensitive filesystem in OS X unless you explicitly choose such. HFS+ can be case-sensitive, but the default is case-insensitive.
Here's a really simple solution around all the gitfoo on this page.
Copy the files out of your project manually.
git rm all the files.
git commit like normal.
add the files back manually.
git add all the files.
git commit like normal.
profit.
Improving Adam Dymitruk's answer (silly that SO doesn't let me comment his answer), using "git mv" will automatically stage exactly the moved files. No stashing is needed and the risky "git add -A" can be avoided:
old="abc"; new="ABC";
tmp="$old-renamed";
git mv "$old" "$tmp";
git commit -m "Renamed '$old' to '$tmp'.";
git mv "$tmp" "$new";
git commit --amend -m "Renamed '$old' to '$new'.";
Here is a simple way of doing it.
Make sure your working directory is empty.
Temporarily disable git ignore case
git config core.ignorecase false
Rename any directories (e.g. Folder => folder)
Add changes to working directory
git add --all
Stash your changes.
git stash
The original directories should be now deleted. Make a local commit.
git add --all
git commit -m "Rename directories"
Pop changes
git stash pop
Amend this to your previous commit.
git add --all
git commit --amend
You should now have a commit with directories renamed. You may now restore the original ignorecase config:
git config core.ignorecase true