0

Assume this is my project structure:

- project
    - .git
    - scr
        - component
            - file.js
  • I did clone the project
  • Made a new branch by git checkout -b "newBranch"
  • Made some changes on file.js
  • Added it to the stage by git add /scr/compoent/file.js
  • Then committed it by git commit -m "some changes"
  • Finally pushed it on the server by git push origin newBranch

From the beginning of my life until now, I only was using git add . for adding changes to the stage. Few mins ago, for the first time, I used git add file.js instead.

After those commands, I went to the GitLab interface -> Repasitory -> File -> newBranch and I saw ONLY file.js there. Also, made a merge request by clicking on create merge request, then assigned it to me (myself) and put master as the destination branch. After merging, the project structure turned out like this:

- project
    - .git
    - file.js              //=> The file contains the changes
    - scr
        - component
            - file.js      //=> This file remained untouched

My question is, why file.js is pasted in the root of the project? How can we apply changes on the real file in such cases instead of creating an instance file (containing changes) and locate it on the root?

stack
  • 10,280
  • 19
  • 65
  • 117
  • 1
    in two separate points of your question you state you run either `git add src/.../file.js` and `git add file.js`. Could you clarify the which and whens? – Daemon Painter Jan 27 '21 at 15:40

1 Answers1

0

This is not what should happen. IMHO you have saved file.js to the root after doing your changes using "Save as..." instead of saving .

There is also something wrong in your description. git add /scr/compoent/file.js seems to be wrong as there should not be leading slash and there is a typo as well.

Using git add scr/component/file.js shoudl work correctly.

Using git add file.js in the top level directory would stage the file in the top level directory that you probably created by mistake...

Always study output of git status before adding and commiting...

Roman Pavelka
  • 3,736
  • 2
  • 11
  • 28