-1

I'm trying to push just the changed files in a project and their related paths to a specific branch in a remote repo. However, I always get all the files in the project. So, if I make a change to resources/views/index.php and I want to have just that folder path and file in a branch limited1, I've been doing this:

git add resources/views/index.php
git commit -m "Path and File only"
git push master limited1

As I said, this puts up all the files in the project into the limited1 branch. How do limit the remote branch to just the changed files and their corresponding paths?

Hitting my head against this wall for several hours now and would any help.

tomtomssi
  • 1,017
  • 5
  • 20
  • 33
Joe Lowery
  • 562
  • 11
  • 26
  • I'm not sure this makes sense - a remote and local branch are supposed to be the same thing (i.e. tracking the same content). What is your use-case where you'd want the local repo to contain different content to the remote repo? – Oliver Charlesworth Mar 13 '16 at 18:59
  • Push already doesn't send duplicate objects, what concrete effect are you trying to achieve or avoid here? Do you intend to make an archive of those files later, or what? – jthill Mar 13 '16 at 19:04
  • I've been asked to do a series of lessons where the tutorial user could look at the files changed in the lesson. For each lesson there will be a starting point and an ending point; both of which would be contained in their own branch. Because of the complexity of the overall project (it's a Laravel project), I want to isolate the files that are worked on but still include their paths so folks can find the similar files on their system. – Joe Lowery Mar 13 '16 at 19:07
  • Looking at changed files is easy, git diff --name-only – jthill Mar 13 '16 at 19:24
  • Not the downvoter, but I think this question would be much improved if you asked the right way to do what you want to do, rather than how to do some specific thing you think might be the right way. – jthill Mar 13 '16 at 20:43

2 Answers2

0

You can create a new branch for this if that is your requirement and then change the .gitignore to ignore all files except the directory path or files you want.

This link will help.

Community
  • 1
  • 1
Milind Gokhale
  • 575
  • 2
  • 14
  • Thanks, Milind. So would I have to adjust .gitignore everytime I wanted to switch to a different set of files? IOW, is there no way to tell Git to ignore everything but the changed path/files? – Joe Lowery Mar 13 '16 at 20:55
0

Git doesn't store changes; git stores content. Every commit is a complete snapshot of every file in the index (staging area) at the time of the commit.

Thus:

$ mkdir new; cd new; git init
$ make-some-files a b c
$ git add a b c; git commit -m first

The first commit has files a, b, and c. Then:

$ append-stuff-to b; git add b; git commit -m second

The second commit has files a, b (modified by appending stuff), and c.

If you want the second commit to have only file b, simply remove a and c before committing:

$ append-stuff-to b; git rm a c; git add b; git commit -m second

When you use git push, git transfers commits (not files) to the remote. The commit contains references to the tree, and the tree contains references to the files. Git computes, on the fly, all the change-sets needed to transform older trees into newer ones, and this includes when doing git push. It actually takes less time and space to send a new commit with just file b modified (one change), than to send a new commit with file b modified and files a and c removed (three changes).

This means that if you think you're saving time and energy and so on by removing stuff, you're wrong: you're making more work for both yourself and git. (That's probably why your question has been down-voted, although not by me.)

torek
  • 448,244
  • 59
  • 642
  • 775