Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update the directory in git

Tags:

git

git-commit

I have a bitbucket repository, with the following structure :

 Directory-A->
   directory a
   directory b
   file a
   file b
   file c

Now I want to move file "b" and file "c" to "directory a"

When I do it on local machine and commit this by git add. I get file b and file c in directory a but they still exists outside it.

like image 852
Shruti Srivastava Avatar asked Jun 12 '15 11:06

Shruti Srivastava


2 Answers

When I do it on local machine and commit this by git add. I get file b and file c in directory a but they still exists outside it.

That is because you did a git add . in directory a instead of a git add -A . in Directory-A.

First, you need to be in Directory-A (the root one) when you do the git add -A . (which is a git add -u + git add .) from the root folder:

Directory-A->  <====== there: git add -A .
   directory a
     file b
     file c
   directory b
   file a

A 'git add -A .' in Directory-A will detect the deletion of those files in Directory-A and their addition in directory a.

See more at "Difference between “git add -A” and “git add .”":

like image 176
VonC Avatar answered Sep 20 '22 21:09

VonC


Here is a better alternative. Try the following:

git mv "file b" "file c" "directory a"

Followed by:

git commit -am "hey I moved filed"

Note: I've only used the -am flag for demonstration purposes. It is not a good practice. You should commit only files with related changes together which makes your repository maintainable.

like image 27
activatedgeek Avatar answered Sep 20 '22 21:09

activatedgeek