When working with Git repositories in Azure DevOps, you might need to move a file from one folder to another without losing its history. The best way to do this is by using the git mv command. This ensures Git recognizes the move as a rename and keeps the file’s commit history intact.
Why Not Use the Web UI?
Moving files in the Azure DevOps web interface creates a new file and deletes the old one, which breaks history tracking. Instead, use Git commands locally.
Steps to Move a File and Keep History
1. Open Your Terminal in VS Code
Make sure you are in the root of your cloned repository.
2. Move the File Using git mv
Run:
git mv apps10\busopp\busopp_details_plus_na.sql beta/busopp
This moves the file from apps10/busopp/ to beta/busopp/ and stages the change.
3. Check Status
Verify the change:
git status
You should see something like:
renamed: apps10/busopp/busopp_details_plus_na.sql -> beta/busopp/busopp_details_plus_na.sql
4. Commit the Change
Add a clear commit message:
git commit -m "Moved busopp_details_plus_na.sql from apps10 to beta"
5. Push to Remote
Push your changes to the main branch:
git push origin main
✅ Verify History
To confirm the file’s history is preserved:
git log –follow beta/busopp/busoppdetailsplus_na.sql
This shows all commits for the file, including before the move.
Key Takeaways
- Always use
git mvfor moves/renames. - Avoid moving files in the Azure DevOps web UI if you need to keep history.
- Use
git log --followto view full history across moves.