Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add files to be committed in a faster way?

Tags:

git

For example, this is the status of a branch in my local repository:

14:56:15 /srv/www/gamersmafia/current[max-decisiones]$ git status
# On branch max-decisiones
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   app/controllers/respuestas_controller.rb
#       modified:   app/helpers/application_helper.rb
#       modified:   app/models/decision.rb
#       modified:   app/models/gm_portal.rb
#       modified:   app/models/term.rb
#       modified:   app/views/respuestas/index.html.erb
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       app/assets/stylesheets/old/sprites/games_sprites.css
#

If I want to add files to commit them, I have to write the path to the file, or select and paste it after writing git add.

Is there a faster way to work with git selecting files to add, checkout, etc? For example, if I just want to add 2 files for commit?

like image 687
Draco Avatar asked Mar 31 '13 13:03

Draco


People also ask

How do you add files to a commit?

To add and commit files to a Git repository Create your new files or edit existing files in your local project directory. Enter git add --all at the command line prompt in your local project directory to add the files or changes to the repository. Enter git status to see the changes to be committed.

How do you add multiple files for commit in git?

To add multiple files in Git, first, navigate to the directory where the untracked files are present and execute the “$ git add” command with the required files name. Then, use the “$ start” command to open added files one by one, make changes and save them.

Which command is used to stage files for a commit?

The git add command adds a change in the working directory to the staging area. It tells Git that you want to include updates to a particular file in the next commit.


2 Answers

You could just add them (also the newly created files) with:

git add -A .

And then commit. If you want to just add some of them you can use add interactively:

git add -i

git will ask for what files you want to add. If you're using linux or a mac you can create an alias in your shell to make the command shorter and so even faster.

Another solution is to use a wrapper for your editor/IDE. You can find a wrapper for almost any developing tool (from eclipse to VIM). This wrappers usually let you perform some actions quickly, just like add or commit the file your editing. You can file a complete list in the git wiki.

like image 156
Atropo Avatar answered Sep 20 '22 20:09

Atropo


To add everything, both tracked and untracked files. Add a dot after add. For example:

git add .

If you just wanted to commit the files that are already tracked without adding new ones, you can use the "-a" flag for git commit. Like:

git commit -a
like image 24
Alan W. Smith Avatar answered Sep 22 '22 20:09

Alan W. Smith