Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git rename all javascript to typescript

Tags:

git

bash

rename

I am migrating all my JavaScript files to typescript, first i need to convert my existing JavaScript file extensions to *.ts

To test i have following command, but this fail: used examples

for f in **/*.js; do
  git mv "$f" "${f%.js}.ts"
done

I always seem to get:

fatal: not under version control, source=jscript/index.js, destination=jscript/index.ts

My final goal is to recursive go to my javascript folder and rename inplace from *.js to *.ts

like image 387
Jan Van Looveren Avatar asked Oct 28 '25 03:10

Jan Van Looveren


2 Answers

Yeay!

The complete sollution in my case is a below, i hope somebody else can use this as well. just place in the root folder of your repo and adjust the folders you work with:

#!/usr/bin/env bash 
shopt -s globstar
for f in /public/jscript/*.min.js public/jscript/**/*.min.js; do
  git rm -r "$f"
done

# convert all the js files to ts files.
for f in public/jscript/**/*.js; do
  git mv "$f" "${f%.js}.ts"
done
like image 149
Jan Van Looveren Avatar answered Oct 29 '25 19:10

Jan Van Looveren


Seems like you forgot to add them to Git. Run :

git add --all :/

After that you should be able to rename. Though I would recommend committing first:

git add --all :/ && git commit -m update

Note: If you haven't even initialized the repo, you will need to run git init before everything else.


EDIT:

As per your comment, it doesn't go into the sub-folders because you probably forgot to use globstar. Add the line

shopt -s globstar

before you use **.

like image 40
Jahid Avatar answered Oct 29 '25 17:10

Jahid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!