How to add unchanged code in Git

673 views Asked by At

I have situation here at my work where we need to add and push couples files as a package. There is one particular file where there is no code change (same as master repo). Git is not recognizing the file and so I am not able to add and push.

2

There are 2 answers

2
SQB On

It seems you misunderstand how Git works.

A commit and a subsequent push serve to add your changes to the repository and share them with your fellow developers. If the file is unchanged, why would you want to commit it?

If you want to want to be able to refer to specific versions of your sourcetree, you could use a tag. Tagging is described in the Git documentation. That may be the "packaging" you're looking for.

But if you want better control over what is deployed where, you need to define a branching strategy.

git branches
(source: nvie.com)

A commonly used strategy is to have a development branch and a master (live) branch. You develop each feature in a separate feature branch, branched off from development. If a feature is completed, you merge that branch back into development. This branch is usually deployed in a test environment which is kept up to date.
When the time comes to release a new version, you branch off a release branch from development. This is your release candidate, which is deployed on a acceptation environment. It's tested there and bugfixed if needed. Those bugfixed get merged back into development.
Once you're ready to release, you merge the release branch into master, tag it with the appropriate version, and deploy that on your production environment.
Hotfixes follow a similar path, but are branched from master, often skip the release candidate phase, and are merged back into both development and master, after which master is tagged with a new minor version.

0
Abhishek On

If you have not done code change in any file, you need not to add and push that file.

That file is already present in your repository and your next commit will not affect that.