2

I have to change the project name and the package name, and I want to avoid breaking the git version control (which is exactly what the management suggests: "just create a new project, we cannot be hostages to git").

It was easy to refactor it under Eclipse (right mouse click -- refactor -- rename), but how do I tell git that the directory names have changed?

$ cd src/com
$ ls
newname
$ git mv oldname newname
fatal: bad source, source=src/com/oldname, destination=src/com/newname/oldname
$ git mv -f oldname newname
fatal: bad source, source=src/com/oldname, destination=src/com/newname/oldname
18446744073709551615
  • 16,368
  • 4
  • 94
  • 127
  • Does it really matter if git thinks it is a new folder? It will remove the other one. Or should do. – Mighty Elemental Jul 20 '15 at 12:12
  • What do you mean? Rename and commit. – Aleksandr M Jul 20 '15 at 12:12
  • Why did you `git mv -f oldname newname`? git should detect it automatically – Tim Jul 20 '15 at 12:12
  • @TimCastelijns you edited the question so that the word "package" has completely lost its meaning: how on Earth is the reader expected to find out that it's a Java/Android package? It is important, the word has many meanings. At 2nd, the Android project name is irrelevant to git, git does not need to care about it, it is ***a string***. The title reads nicely, but it's nonsense. At 3rd, you edited the question thinking you know the right answer. If the things worked that easy, if people could ask the right questions, I would find the answer in the docs. SO collects real questions. – 18446744073709551615 Jul 20 '15 at 14:11
  • 1
    1) The word "package" has meaning for sure, but not to Git. The question is (or, appears to be) about Git detecting name changes of an entire project. Readers don't need to know that you're working on a java/eclipse/android project, it applies to many more situations. 2) I'm just trying to help you out here. The title may not be great now, but it was worse before I edited it. 3) I never said I was an expert or know the answer to your problem. Don't be so hostile. It's not a great feeling when you're trying to help someone and they piss on your efforts. – Tim Jul 20 '15 at 14:26
  • If you don't agree with my edit, you can rollback to a previous state. – Tim Jul 20 '15 at 14:27

2 Answers2

2

Just do

git rm oldname
git add newname
git commit -m "renamed oldname -> newname"

Git will detect the renaming automatically.

For coping with the new history see these:

Community
  • 1
  • 1
eckes
  • 64,417
  • 29
  • 168
  • 201
  • Before I committed, I saw `renamed: oldname/Xyz.java -> newname/Xyz.java` and that was inspiring. But now, after committing, I try to see the history of changes, and it's gone: both GitLab and `git log` now show only 1 commit. How do I view the history of changes in a file now? – 18446744073709551615 Jul 20 '15 at 13:38
  • `git log --follow` works, GitLab does not. OTOH, there are good chances that I will never need to dig in this old [stuff]. Anyway, git does automatically detect renames. – 18446744073709551615 Jul 20 '15 at 14:17
  • @18446744073709551615: there's an open ticket regarding this functionality in gitlab: https://github.com/gitlabhq/gitlabhq/issues/7832 – eckes Jul 20 '15 at 14:22
0

You don't.

Git is always looking at files not at folders (that's why you do not have empty directories).

If you change it in eclipse it should already be ok. Check with git status if you see the move.

szefuf
  • 500
  • 3
  • 14
  • I see: `deleted: oldname/(a lot) untracked: newname` – 18446744073709551615 Jul 20 '15 at 12:18
  • That's weird… you should see: `renamed: /oldPath/file -> /newPath/file` But if you have `untracked` then use `git add` to make git track the files Also, you cannot `git mv` because files are already _not there_ – szefuf Jul 20 '15 at 12:33