I start with empty directory:
git clone --no-checkout <repository> <directory>
I have the following parameters:
<remote>- branch for pull request (not HEAD), e.g.integration<filepath>- path to file to update, e.g.version.txt
What should be the next steps?
Update:
Finally, the following worked for me:
# clone and create local branch named <remote> from <remote>
git clone --no-checkout --branch <remote> <repository> <directory>
cd <directory>
# checkout only one file
git checkout <remote> -- <filepath>
edit <filepath>
# commit only one file
git commit -m <message> -- <filepath>
# push local branch to a new remote branch
git push origin <remote>:refs/heads/<remote>-edit
However, this script works only for one branch per repository. If more than one branch should be updated this way, some git reset is still required.
CodePudding user response:
You weren't explicit in your question, so I'm going to assume you're working with a repository on GitHub.
If you're trying to avoid checking out all the files in a large repository, it might be easiest to just edit the single file through the github web ui, since this way you don't need to clone the repository to your local filesystem.
If that's not an option, then maybe something like this would work:
Fork the repository on GitHub
Clone your fork of the repository:
git clone --no-checkout <repository> <directory>Change into the working directory:
cd <directory>Reset the repository state (because of the
--no-checkout, all files in the repository will initially be staged for deletion):git reset HEADCreate a new branch for your work:
git checkout -b my-new-featureCheck out the file you want to modify:
git checkout HEAD src/main.cMake your changes:
vim src/main.cStage those changes for a commit:
git add src/main.cCommit the changes:
git commit -m "Add awesome new feature"Push the changes to the remote repository:
git push -u origin HEADMake a pull request from that branch to the target branch.
