I have a bit of a tricky problem. I restarted a current rails project from scratch in a new folder because I was redoing the app as a personal exercise. We've run into some issues on the 'official' version and now need to restart the project.
The problem is that we've been using git to keep track on the official project but I haven't been using it for my personal version.
I've branched the official git master repository using
git checkout -b restart_app
Now I'd like to clear out all the code in that branch and replace it with my personal version. I've tried to google the best approach to doing so but found some differing answers and I'm pretty new to working with git so I thought I'd put up a question here. What would be the best practice/solution for approaching this problem?
"I want replace all the files in restart_app with files from a different project folder"
Delete and replace the files by the ones you want.
The best practice is to do a git rm * first, then add your files, git add and commit.
A nice trick, you can use the --work-tree option of git:
git checkout restart_app
git rm -rf .
git add -A .
git commit -m "empty restart_app"
git --work-tree=/path/to/untracked/code add .
git commit -m "add new code"
Related
Suppose that you have a repository in bitbucket and you need to create a new folder inside the bitbucket repository and move your files there.
The way that I am moving it removes history, all the previously saved files in the repository and replaces the new one.
I found some similar questions here but they are old and they did not work out for me.
Please advise!
Edited: the wat that I am doing :
git init
git add .
git commit -m "my new commit"
git remote add origin https://.....
git push -f origin master
This removes any other code.
Git tracks exactly what matters, namely "collections of files".
git mv oldname newname is pretty much like mv oldname newname; git add newname; git rm oldname
It mostly depends on your client I think to track renaming of files. Sometimes it works, but if the content is changed drastically then it considers it as a new file.
An other question on here that discusses this issue.
What's the purpose of git-mv?
Update:
https://git.wiki.kernel.org/index.php/GitFaq#Why_does_Git_not_.22track.22_renames.3F
As a very special case, 'git log' version 1.5.3 and later has '--follow' option that allows you to follow renames when given a single path.
Mail by Linus on this topic.
Git has a rename command git mv, but that is just for convenience. The
effect is indistinguishable from removing the file and adding another
with different name and the same content.
I accidentally did a git.init on a parent folder of my app (Rails project). I didn't realise until a long way into my development when I now wish to deploy to Heroku.
My folder structure is ~/project/project/app with git initialised in ~/project/app.
Heroku states:
"Heroku apps expect the app directory structure at the root of the
repository. If your app is inside a subdirectory in your repository,
it won’t run when pushed to Heroku."
So, I'm trying to undo this, without much success.
I tried moving all the folders of my app up a level, so from project/ I did the following command:
mv project/* project/.* .
This seemed to move a copy of everything up a level, into my ~/project folder, however, in terms of Git, only the still nested files (in ~/project/project/) are the branch specific files (as tested by switching branches and looking at both sets of files in my text editor).
I copied the files when my git branch was specified as the master branch. Does this mean I've only copied the "master branch" files. This is where my knowledge of git is limited.
Any help much appreciated.
** note, i have a copy of my folder or can re-clone from github.
If you don't have a problem to re-publish your repo (git push --force, meaning you will change the history of commits, and other will have to fetch and reset their local branches), you can refer to "How can I move a directory in a Git repo for all commits?".
Use git filter-branch in order to affect all commits of all branches:
git filter-branch --tree-filter \
'test -d project/app && mv project/app . || echo "Nothing to do"' HEAD
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.
I decided to learn how to use Version Control over Christmas break, so I downloaded Git, opened a GitHub account and started reading the online tutorial linked to from the GitHub website. When I got to this part http://progit.org/book/ch2-2.html I got stuck because I wasn't sure how to add files. For instance, I tried
git add C:/Finish.txt
And it said
Fatal: 'C:/Finish.txt' is outside repository
I was confused until I remember that a long time ago I had tried teaching myself Ruby on Rails and played around with Git back then. It never really went anywhere, but there's all this residual stuff floating around my system and I don't know how to change it. For instance, my Untracked files (which should be empty) are rails_projects/ and sample/.
How can I just erase all the old stuff and start over?
You should make a folder for your repository, move Finish.txt to that repository, then do git add.
For example:
# here you create C:\myrepo
cd C:\myrepo
git init .
# here you edit C:\myrepo\Finish.txt
git add Finish.txt
git commit -m "Added Finish.txt"
Start a new repository, e.g.
c:
md c:\newrepo
cd c:\newrepo
git init .
copy \Finish.txt .
git add Finish.txt
git commit -m "started over"
I strongly recommend against adding anything to C:\, let alone putting a git repo there. Unless of course you want to accidentally add all of your system disk to git :)
I can also heartily recommend using TortoiseGit which has some excellent explorer integration.
Delete any .git folder that you find in your drive.
To create a repo go to a folder that you want the repo in ( and not just randomly), do:
git init
Then proceed... Add only files that you put within this repo and not randomly from some location.
It would be very unusual to have the root directory of your hard drive be a git repository. That's probably why it's giving you the error.
git repositories are typically in a subdirectory and that subdirectory is typically a project.
To initialize a subdirectory as a git repository, you'd do:
git init (directory)
Then you'd add your files and commit.
I just started using Git and I want to know if this is the right way of using it. I started a Rails app with:
rails newapp
Then I did:
cd newapp
git init
git add .
git commit -a
So is it "right" to init my git inside my working directory?
Yes. You can place a git repository anywhere - including the invisible .git directory created by another git repository. I have a friend who has git track all his system config files in case he makes a mistake.
When working on a project, you want to init your repository in the root directory of the project.
To elaborate, each "working copy" of a Git repository is itself a Git repository. If you have a remote copy on a server, that is also a repository. You don't "check out" from there - rather, you "push" your changes and they are merged. If working on a purely personal project, the remote repository is often unnecessary. If you do want to host remotely, Github is a good, free, public choice.
Yep. Looks good to me.
Yes. In a DCVS like git, your working copy is your repository.