Questions tagged [git-mv]

git-mv is a git command that is used to move or rename a file, a directory, or a symlink

- Move or rename a file, a directory, or a symlink. The index is updated after successful completion, but the change must still be committed.

38 questions
511
votes
14 answers

Handling file renames in Git

I'd read that when renaming files in Git, you should commit any changes, perform your rename and then stage your renamed file. Git will recognise the file from the contents, rather than seeing it as a new untracked file, and keep the change…
Greg K
  • 10,770
  • 10
  • 45
  • 62
395
votes
9 answers

What's the purpose of git-mv?

From what I understand, Git doesn't really need to track file rename/move/copy operations, so what's the real purpose of git mv? The man page isn't particularly descriptive... Is it obsolete? Is it an internal command, not meant to be used by…
Mauricio Scheffer
  • 98,863
  • 23
  • 192
  • 275
47
votes
2 answers

git copy file, as opposed to `git mv`

I realize that git works by diff'ing the contents of files. I have some files that I want to copy. To absolutely prevent git from ever getting confused, is there some git command that can be used to copy the files to a different directory (not mv,…
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
13
votes
2 answers

Git: moving submodules recursively (nested submodules)

I have the following git structure - git-repo a -- subdirectory 2015 --- git-submodule b -- git-submodule c --- git-submodule d I would like to move the git submodule c to the folder 2015. I know of "dirty ways" to do this (that involve modifying…
BartBog
  • 1,889
  • 14
  • 28
8
votes
3 answers

Practical use case of 'git rm' and 'git mv' with git?

I know that git provides the 'git rm' and 'git mv' to remove/move files or directories. But, I can't see the practical use case for this. Normally, I just mv or rm the files or whatever in the command line, and after I'm done with all the necessary…
prosseek
  • 182,215
  • 215
  • 566
  • 871
6
votes
1 answer

git mv and changes and similarity index

When a file is renamed with git mv, the commit will show rename from and rename to, and in pull request shows the same, which is good. But when a file is git mved then changed, it looks there is a certain threshold that when number of lines changed…
fluter
  • 13,238
  • 8
  • 62
  • 100
6
votes
2 answers

Is there a difference between git mv and the MS-DOS move?

Question Does it make a difference if I move Git tracked files with the git mv command as opposed to just moving the files with MS-DOS move or the Windows Explorer? Back in the Subversion days, it was necessary to use for example the TortoiseSVN SVN…
Lernkurve
  • 20,203
  • 28
  • 86
  • 118
4
votes
1 answer

Trying to understand `git diff` and `git mv` rename detection mechanism

This is a followup to another question I asked before. Before being edited, the initially created file something gets renamed to somethingelse which can be observed here: git mv something somethingelse The file somethingelse then gets renamed back…
Christian Heinrichs
  • 786
  • 1
  • 9
  • 28
3
votes
1 answer

git merge after renaming of all files

There are other answers regarding handling merge for a rename, but my case is complicated enough that I thought it warranted a separate question. We have a git project that originally consisted of 20+ repositories. We used a wrapper script to…
tanager
  • 189
  • 2
  • 10
3
votes
5 answers

unable to commit a file, accidentally renamed with mv

I've accidentally used mv to rename a file which was under git. I renamed the file from lower case to uppercase keeping the name same. mv abc.java ABC.java I've also made changes and committed the file after that . How do I now make an actual git…
A.R.K.S
  • 1,692
  • 5
  • 18
  • 40
2
votes
0 answers

How to change a deleted/untracked file to a git mv?

I reset the top of my local git branch. In that check-in I moved a file using git mv, now it shows that the file has been removed and the file is located in the untracked file list. If I readd the file and check it in, will it think that it's a…
Adrian
  • 10,246
  • 4
  • 44
  • 110
2
votes
1 answer

Does git mv folder and merge afterward new file from feature branch to the modified path, deletes its history?

I have the below scenario: main branch before consolidation: │ └── dir1 │ │ └── python1 │ │ │ └── test1.py │ └── dir2 │ │ └── python2 │ │ │ └── test2.py │ └── dir3 │ │ └── python3 │ │ │ └── test3.py main branch…
arielma
  • 1,308
  • 1
  • 11
  • 29
2
votes
1 answer

Git mv doesn't work as expected (wrong files location)

As part of task I have, I need to consolidate components from three places to one place. In other words, move folders (which include many subfolders and files) to one existing folder. I'm doing it using git mv, but the issue is that, once I'm trying…
arielma
  • 1,308
  • 1
  • 11
  • 29
2
votes
0 answers

How can I fix a renamed file if I forgot to run `git mv`?

I reset my branch to an earlier commit, keeping changes, using a graphical git app. However what was previously a moved file (git mv Anchor.jsx Anchor.tsx) has become an add and a delete: $ git status git status On branch…
mikemaccana
  • 110,530
  • 99
  • 389
  • 494
2
votes
2 answers

How to move directory to another directory using git

I have one directory 'Checkout' that needs to move to the directory 'screens'. I do not want to overwrite the screens folder, I just want to add Checkout to it. This is all on local machine. So far I have created and navigated to a new branch. The…
Ronald
  • 508
  • 6
  • 24
1
2 3