Reputation: 31347
Sometimes, some files, appear on a working tree. They are untracked,
Some of those files we wish to discard and NOT stage them, others, however, we may want to stage them.
My question is: Is there some sort of interaction command that we may use to select, by steps, what files we want to keep, and what files we want to disregard?
Hope my question is clear.
Upvotes: 4
Views: 633
Reputation: 49543
You could play around with git add -i
to interactively stage files.
$ git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# a
# b
# c
# d
nothing added to commit but untracked files present (use "git add" to track)
$ git add -i
staged unstaged path
*** Commands ***
1: status 2: update 3: revert 4: add untracked
5: patch 6: diff 7: quit 8: help
What now> a
1: a
2: b
3: c
4: d
Add untracked>> 2
1: a
* 2: b
3: c
4: d
Add untracked>> 4
1: a
* 2: b
3: c
* 4: d
Add untracked>>
added 2 paths
*** Commands ***
1: status 2: update 3: revert 4: add untracked
5: patch 6: diff 7: quit 8: help
What now> s
staged unstaged path
1: +0/-0 nothing b
2: +0/-0 nothing d
*** Commands ***
1: status 2: update 3: revert 4: add untracked
5: patch 6: diff 7: quit 8: help
What now> q
Bye.
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: b
# new file: d
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# a
# c
Although a bit off-topic I just wanted to add this information:
git add -i
is far more powerful that the above usage case. For example, if you want to add only part of the changes in a file, you could use the patch
mode.
I have used the patch mode, hell a lot of times when I've realized that I want to break the changes in a single file into 2 separate commits, but I do not want to manually create a copy of the file, edit the original, stage, commit and do the same again for the next commit.
In patch mode, git gives you options to break the changes into smaller patches and stage only those hunks. If git doesn't give you the best hunk automatically, you can manually break down the hunks yourself in an editor prompt.
Upvotes: 5
Reputation: 93860
You can use git add -i -A
to get an interactive prompt for untracked files. Select 4: [a]dd untracked
and then toggle inclusion of files in the list by number or shortcut letter.
Not sure what you mean by "compare two repositories". Any repository can use git fetch
to add the contents of any other repository and then compare the resulting revisions (or in the case of the working repo, modified files) with git diff
.
Upvotes: 1