开发者

How to use Git in SVN-like fashion?

I like the simplicity of Git but I'm having a hard time using it effectively.

Is it possible to do the following with Git (on my local development machine):

  1. Have a repository in some directory like SVN (D:\gitrepo)
    • I'm afraid that I may accidentally delete my entire git repo for a project (all it takes is deleting one folder and everything is gone)
    • Having a separate out-of-the-way directory gives me some comfort.
    • It's easier to manually backup one folder rather than many
  2. Have git branches in separate directories
    • So that I can Beyond Compare them easily
    • So I can see what branches I have easily

开发者_如何学GoAny suggestions on how to proceed with the above in git?


To setup a repository like D:\gitrepo, you use what are called remotes. You would use this directory as a remote that you and other developers can use as the "Central SVN-like server". Create the gitrepo directory, and run the command git init --bare. Then from your local git repo you can do git remote add origin D:\gitrepo. Then you push via git push origin master. Now anyone can clone from D:\gitrepo and push their changes back up.

I'm not sure what you mean by "(all it takes is deleting one folder and everything is gone)". If you delete your src/ folder, your data isn't gone. You can easily roll it back with git reset --hard HEAD assuming you didn't commit it. If you did commit it use git revert SOMESHA. Obviously SOMESHA is the SHA1 hash for the commit. If you accidentally delete D:\gitrepo, that's not a problem because your working copy is exactly the same. Just do what I said in the first paragraph again. The only way to lose everything is if you delete the remote repository and all of the repositories cloned from it.

For backups, you just need to backup the entire D:\gitrepo folder.

For your second point, there is no easy way to have branches in separate directories. The best you can do is to have two clones, and set each clone to a different branch. I'm not familiar with Beyond Compare, but git diff works between two branches without require separate directories. Just use git diff master somebranch. To see which branches you have, use git branch


You are definitely trying to use it in a way it wasn't designed for; that being said...

1) yes, you can have mulitiple copies of a repository around so you can 'git push' to another one as a backup if you like. Set up the other one using 'git init --bare' though.

2) You can have multiple cloned repositories next to each other and push/pull branches between them. However, in the end I think this will cause you significantly more work. 'git branch' easily lists all your available branches already.


For having branches in different directories, you can use the git-new-workdir script. This shares one repository between multiple working directories, which can be positioned at different branches.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜