简体   繁体   中英

Move a file from a git repository to a working folder?

I've created a local git repo, and uploaded to GitHub. It is housed in a local folder named ~/GitHub/WhatAreTheOdds . The repo/folder contains one executable file named oddsr.sh (a shell script), and an assortment of "support files" (README, wiki, license, etc, etc).

I want to keep oddsr.sh in a location outside the git repo folder - in a folder called ~/scripts . I have other scripts in ~/scripts , and subfolders containing output data. It is just more convenient for me to work with oddsr.sh from the ~/scripts folder.

I will occasionally make edits to ~/scripts/oddsr.sh . When I make these changes, I would like for them to be picked up by git so that I am prompted to synchronize my local repo with GitHub. I use the GitHub Desktop app for this.

Is it possible for git (or more specifically the GitHub Desktop app) to include the file ~/scripts/oddsr.sh in the repo? I do not want to maintain an additional copy in ~/GitHub/WhatAreTheOdds/oddsr.sh

It seems to me this would be common practice, but perhaps not. I've searched, but I may be using the wrong terms to describe what I want to do. I have read a piece about git mv , but after some reading, it's not clear this will do what I want.

Can I keep a file outside the git repo, yet have git maintain version control over it?

Use can just go to your shell (terminal, Git Bash, etc.), then navigate to your repository. Then type

git mv ~/GitHub//WhatAreTheOdds/oddsr.sh ~/scripts/oddsr.sh

This will move your file to the scripts folder.

Simple answer is NO.

git only tracks everything inside the root folder where repo is initialized.

eg:

> cd my_repo
> git init

After the above command, git will track all files inside my_repo folder only. If you want to track anything outside this repo, you won't be able to do this, as git doesn't have any knowledge of files outside it's root folder(in this case my_repo ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM