Git pushes entire project even if few files are ch

2019-06-28 01:01发布

问题:

I am using Git to push our application to AWS though Elastic Beanstalk. AWS has created the means to do this, although from my understanding it is not exactly a traditional repository. So, for example, I can't pull from my Beanstalk project.

I am confused about what is happening during a push and why sometimes it is pushing much more data than others. My typical process is as follows

//create, edit files
$ git add .
$ git commit -m "message here"
[master 7d38f1f] message here
 5 files changed, 27 insertions(+), 19 deletions(-)
$ git aws.push
Counting objects: 5131, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (4930/4930), done.
Writing objects: 100% (5131/5131), 40.70 MiB | 391.00 KiB/s, done.
Total 5131 (delta 1487), reused 0 (delta 0)
remote: processing 
To https://exampleLocation
+ 7f9d9dd...7d38f1f HEAD -> master (forced update)

Now maybe I'll edit a few files and do another push. This time it will be much smaller/faster

$ git add .
$ git commit -m "message2"
[master e2f4412] message2
 1 file changed, 1 insertion(+)
$ git aws.push
Counting objects: 9, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 472 bytes | 0 bytes/s, done.
Total 5 (delta 3), reused 0 (delta 0)
remote: 
To https//exampleLocation
7d38f1f..e2f4412  HEAD -> master

Tomorrow, when I do my first push, it will might be the big one again...

This question alludes that only changes are sent, and in the above example you can see that to be true. However, tomorrow when I come in to work my first push will likely be similar to the first one. So somebody is losing track of what has been changed. How can I get it to remember?

Thank you

回答1:

I was mistaken with my original answer. Here's the updated version.

As we can see from .git/config

[alias "aws.elasticbeanstalk"]
        remote = !.git/AWSDevTools/aws.elasticbeanstalk.push --remote-url
        push = !.git/AWSDevTools/aws.elasticbeanstalk.push

[alias "aws"]
        push = !git aws.elasticbeanstalk.push

git aws.push is an invocation of .git/AWSDevTools/aws.elasticbeanstalk.push Ruby script, which among other code contains the following:

commit = opts[:commit] # if commit is specified with --commit
commit = 'HEAD' if commit.nil?

destined_env = opts[:env] || AWS::DevTools.environment()
if !destined_env.nil?
  puts "Pushing to environment: #{destined_env}"
end
`git push -f #{remote} #{commit}:refs/heads/master`
status = $?.exitstatus
exit status

In your first log you see the note - (forced update), which you don't see in the second log. Let's look deeper into "forced update".

From git-push manual:

-f
--force
Usually, the command refuses to update a remote ref that is not an ancestor of the local ref used to overwrite it. This flag disables the check. This can cause the remote repository to lose commits; use it with care.

Remote ref might not be an ancestor in at least two cases:

  • when it is the ref itself, when attempting to push the same commit
  • when someone else updated the remote repository and your commit have to overwrite their changes

I believe that one of those cases is yours.

Or it might be a bug in AWS tools. Previously there was another issue, with remote repository not being updated after the changes were made locally. Maybe that was the fix - to use force with push.

I'm going to dig deeper into the issue, and will update the answer once I have more information.