【问题标题】:Move git directory a folder up while maintaining history将 git 目录向上移动一个文件夹,同时保持历史记录
【发布时间】:2023-03-23 01:47:01
【问题描述】:

我不小心选择了我项目的 Git 文件夹

e:\programs\trimetric game\trimetric game

不是一个文件夹,而是

e:\programs\trimetric game

我想将 Git 存储库移动到上一个文件夹中,因为 Visual Studio 会跟踪 Git,但仅当它位于该文件夹中时。我不确定如何做到这一点,同时仍然保留我以前的所有提交,就好像它们发生在层次更高的文件夹中一样。

另外,这个项目在 GitHub 上,我不确定这些更改是否会影响它。

【问题讨论】:

标签: git visual-studio


【解决方案1】:

编辑因为评论显示我一开始误解了这个问题

第一:只要你不删除远程分支(或push -f,基本相同),你的github repo是安全的:你不会丢失数据。

现在,做你想做的事,你可以:

cp -r "e:\programs\trimetric game" "e:\programs\trimetric game.backup" #better safe than sorry
cd "e:\programs\trimetric game\trimetric game"

#Start to make the repo look like what you want
mkdir "trimetric game"
git mv * "trimetric game"
cp -r ../* .
git add . #Add to git those files we've just added
git commit -am "Changing the structure of the repo"

#Now move it up
#We could use mv, but here is a simpler approach
git push origin master #or work with another branch if you don't want to change master now
cd ../..
rm -rf "trimetric game" #We delete everything because we've backed up everything on github
git clone "https://github.com/xxx/trimectric game" 

【讨论】:

  • 我的意思是我希望 git 监控“e:\programs\trimetric game”而不是其中的文件夹,但不要在里面移动任何东西。
  • 那我误解了你的问题。因此,我编辑了我的答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-29
  • 1970-01-01
  • 2014-04-26
  • 2012-08-06
  • 1970-01-01
  • 2015-10-21
相关资源
最近更新 更多